Page 1 of 1

Using Image Areas

Posted: Mon Feb 02, 2015 4:05 pm
by calmrr3
Hello,

I wonder if someone could help me with the following:

I have a card which generates a visual using graphics, on this card is a button which is meant to send a screengrab of the generated visual to an Image Area on another card. I am trying to figure out how I can check the image fields to see if they are empty or not so that the generated visual gets placed in an empty image area and once all of the 9 image areas are full then it should clear them and place the generated visual into the first image area.

Image empty areas are laid out on a card like this:
Image

Once an image has been added to image areas I want to be able to find the next available empty image area (I can't use a repeat loop because the images are being generated and set to the image areas when the user chooses and not all at once.
Image

I have a button on the same card where the visuals are generated with this script (at the moment I am just trying to get two images in):

Code: Select all

on mouseUp
   if img 1 of card "manualS" is EMPTY then 
      EXPORT snapshot from rect 0,20,320,340 of this card to img 1 of card "manualS" of this stack
   else if img 1 of card "manualS" is not EMPTY then
      EXPORT snapshot from rect 0,20,320,340 of this card to img 2 of card "manualS" of this stack
   end if 
   go to card "manualS"
end mouseUp
Thanks!

Re: Using Image Areas

Posted: Mon Feb 02, 2015 4:45 pm
by calmrr3
Worth mentioning that when I run this it says:

Code: Select all

   NO SUCH OBJECT  >>  EXPORT snapshot from rect 0,20,320,340 of this card to img 2 of card "manualS" of this stack
I assume this is referring to 'img 2' which doesn't make sense to me as surely that refers to the second image area on card "manualS"

Re: Using Image Areas

Posted: Mon Feb 02, 2015 5:02 pm
by Klaus
I assume that was only an EXAMPLE and you were smart enough to give your image objects meaningful names with numbers!? :D

Why not write a little function that return the first EMPTY image object on your target card?

Re: Using Image Areas

Posted: Mon Feb 02, 2015 5:45 pm
by dunbarx
Klaus.

How do you know that an image is empty? Is the content of an image determinable by some property? I do not mean the "text" of the image, which I have never understood, and is a nightmare of odd data.

Unless you meant to test if there is any image at all present at the various locs of the fixed areas on the card.

Calmrr3, In any case, Klaus' thinking seems like the right course to me as well. If there is a simple image property that can be tested, fine. If not, then track the inclusion and deletion of images on the card. Since you explicitly load and unload images to those areas, you can keep a census as you go. This is simple and straightforward.

For example, perhaps the "blank" images could be fixed square graphics that you populate with images. You might set a custom property that keeps track of whether or not a graphic has been loaded or cleared. Then you can add new images to the lowest numbered graphic region available.

Craig Newman

Re: Using Image Areas

Posted: Mon Feb 02, 2015 5:58 pm
by Klaus
Hi Craig,

empty images:
1. do NOT have any filename
AND
2. and their TEXT is empty
I think with this combination we can check if an image is really "EMPTY" :D


Best

Klaus

Re: Using Image Areas

Posted: Mon Feb 02, 2015 6:44 pm
by dunbarx
Klaus.

OOOH. Cool. Never worked much with images. So all that text trash actually translates to real content. I just never knew that was the property that contained the (what?) bitmap of the image contents? Makes sense, I suppose.

So calmrr3 would not actually import images, but rather simply set the text of the lowest layered empty one to the text of the image he wants to load?

Then that is your answer. Now you can set properties instead of creating objects. You still need a repeat loop, but just to find the lowest layered image that has an empty text property. The layering never changes, and you set the text to the lowest layered image that comes up.

Craig

Re: Using Image Areas

Posted: Mon Feb 02, 2015 7:03 pm
by dunbarx
There is a similar thread on empty and erased images in the use-group.

Craig

Re: Using Image Areas

Posted: Mon Feb 02, 2015 9:04 pm
by calmrr3
Hi thanks for your replies, i'm still struggling to figure this one out. Each image is named "Image1" "Image2" ... "Image9"

I've included some code below which livecode doesn't seem to like (it says the if statement is missing 'then').

The thing I can't work out is: with a repeat will the image be exported into ALL the empty image areas or just the first one it finds (hence the exit loop comment in the script).

Code: Select all

on mouseUp
   
   repeat with checkImgs = 1 to 9
      
      if img "Image" &  quote & checkImgs & quote of card "manualS" is EMPTY then 
         EXPORT snapshot from rect 0,20,320,340 of this card to img "Image" & quote & checkImgs & quote of card "manualS" of this stack
      else if img "Image" & quote & checkImgs & quote of card "manualS" is not EMPTY then
         EXPORT snapshot from rect 0,20,320,340 of this card to img "Image" & quote & checkImgs & quote of card "manualS" of this stack
      end if 
      
      // exit repeat when image is exported?
      
      
   end repeat
   
   go to card "manualS"
   
end mouseUp


Thanks again!

Re: Using Image Areas

Posted: Mon Feb 02, 2015 10:21 pm
by Simon
I take it that checkImgs contains a number
if img "Image" & quote & checkImgs & quote of card "manualS" is EMPTY
is
if "Image""2"...
you want Image1, Image2 etc

If img ("Image" & checkImgs) of card...

Simon

Re: Using Image Areas

Posted: Mon Feb 02, 2015 10:35 pm
by dunbarx
Hi.

What Simon said. And he uses very good form in enclosing the "image" & checkImgs in parentheses. This makes the concatenation much easier to read, even though those parens are not really required. It should make you see more readily why those extra quotes were tripping you up.

Craig

Re: Using Image Areas

Posted: Mon Feb 02, 2015 11:57 pm
by calmrr3
Hi,
So I now have:

Code: Select all

on mouseUp
   
   repeat with checkImgs = 1 to 9
      
      if img ("Image" & checkImgs) of card "manualS" is EMPTY then 
         EXPORT snapshot from rect 0,30,320,350 of this card to img ("Image" & checkImgs) of card "manualS" of this stack
      end if 
      
   end repeat
   
   go to card "manualS"
   
end mouseUp
but this is adding the image to all 9 empty image areas, am I missing something?

Thank again

Re: Using Image Areas

Posted: Tue Feb 03, 2015 12:06 am
by dunbarx
Hi.

If you have a successful test of an image, you will want to exit the repeat loop (pseudo):

Code: Select all

repeat
  if empty then
    export
    exit repeat
  end if
end repeat
read up on the "exit repeat" control structure in the dictionary. This is a critically important tool.

Craig

Re: Using Image Areas

Posted: Tue Feb 03, 2015 12:07 am
by SparkOut
Yes, you already surmised with your comment in a previous post. Within the if condition, after exporting the snapshot but before the end if

Code: Select all

exit repeat
. At least that's one way of doing it.