Page 1 of 1

Showing an imported image into an imagearea

Posted: Mon Sep 29, 2014 10:58 am
by Weaksafety
Hi,

Let's say I have a few images that are already imported as controls in my stack, with their visible set to false.

I created a group with an image field, that should behave like a pop-up (so it becomes visible upon clicking a button) and display just one of the pre-imported images; the name of the image is passed on by the button.

Code: Select all

on showPopover pTitle, imageName
   set the text of field "titoloPopup" of group "gruppoImmagini" to pTitle 
   set the location of group "gruppoImmagini" to 1280/2, 800/2
   put the short ID of image imageName into idimag
   --set the imagesource of image "imgPopup" to image imageName //doesn't work
   --set the imagedata of image "imgPopup" to the imagedata of image id idimag //doesn't work
   --set the ID of image "imgPopup" to idimag //doesn't work
   --put image imageName into image "imgPopup" //doesn't work
   set the visible of group "gruppoImmagini" to true
end mostraPopover


Now as you can see I'm surely using the wrong syntax. Can you help me out figuring out the right one?
Thanks!! :D :D :D

Re: Showing an imported image into an imagearea

Posted: Mon Sep 29, 2014 11:20 am
by LCNeil
Hi Weaksafety,

I created a quick sample stack (with the below script) and the included image setting methods worked as expected-

Code: Select all

on mouseDown
   showPopover
end mouseDown

on showPopover
      set the text of field "titoloPopup" of group "gruppoImmagini" to "test" 
      set the location of group "gruppoImmagini" to 247, 379
      --set the imagedata of image "imgPopup" to the imagedata of image "test2"
      --put image "test2" into image "imgPopup" 
      --set the text of image "imgPopup" to the text of image "test2"
      set the visible of group "gruppoImmagini" to true
end showPopover

on mouseUp
    set the visible of group "gruppoImmagini" to false
end mouseUp
I would be careful if using the imagedata property. The following is a note taken from the LiveCode dictionary-
Important! When changing the imageData property, make sure the new data is the correct size: 4 bytes per pixel in the image. If you set an image's imageData property to data whose total length is incorrect, the image appearance will be distorted.

The imageData property is related to the content of the image--changing either one changes what's displayed in the image--but they're not identical: the imageData property and the image content are in different forms, have different sizes, and include overlapping but not identical information about the picture.

The imageData, unlike the contents of the image container, is based on the picture as it's presented on the screen, not stored in the image object. This means that if you resize an image, the content of the image does not change, but its imageData does. If you create an image and then reduce its size, its imageData reflects the scaled-down, displayed image, not the original full-scale image. If you create a second image and set its imageData property to the imageData of the original image, resizing the first image back to the original dimensions displays the original image at full resolution, but resizing the second image does not, because setting its imageData transferred only the scaled-down version of the original.
Kind Regards,

Neil Roger
--
LiveCode Support Team ~ http://www.runrev.com
--

Re: Showing an imported image into an imagearea

Posted: Mon Sep 29, 2014 11:32 am
by dave.kilroy
Hi weaksafety

Are you by any chance storing your imported images on a different card? If so then all you need to do is to reference that card and use a simple 'put' statement as in:

Code: Select all

put img imageOne of cd anotherCard into img imageTwo

Re: Showing an imported image into an imagearea

Posted: Mon Sep 29, 2014 12:36 pm
by [-hh]
And yet another method:
You wish to display one of N images? You could simply set the visible of exactly this one to true. This doesn't change any other image property if the loc of the image is already OK.

Code: Select all

local imageNames="pict0,image1,bild2,imaggini3" -- all imageNames
on showImage oneName
  lock screen; lock messages
  repeat for each item iName in imageNames
    set visible of image iName to (iName is oneName)
  end repeat
  unlock screen; unlock messages
end showImage iName