Using Image Areas

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Using Image Areas

Post by calmrr3 » Mon Feb 02, 2015 4:05 pm

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!

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Using Image Areas

Post by calmrr3 » Mon Feb 02, 2015 4:45 pm

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"

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Using Image Areas

Post by Klaus » Mon Feb 02, 2015 5:02 pm

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?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Using Image Areas

Post by dunbarx » Mon Feb 02, 2015 5:45 pm

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

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Using Image Areas

Post by Klaus » Mon Feb 02, 2015 5:58 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Using Image Areas

Post by dunbarx » Mon Feb 02, 2015 6:44 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Using Image Areas

Post by dunbarx » Mon Feb 02, 2015 7:03 pm

There is a similar thread on empty and erased images in the use-group.

Craig

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Using Image Areas

Post by calmrr3 » Mon Feb 02, 2015 9:04 pm

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!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Using Image Areas

Post by Simon » Mon Feb 02, 2015 10:21 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Using Image Areas

Post by dunbarx » Mon Feb 02, 2015 10:35 pm

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

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Using Image Areas

Post by calmrr3 » Mon Feb 02, 2015 11:57 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Using Image Areas

Post by dunbarx » Tue Feb 03, 2015 12:06 am

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
Last edited by dunbarx on Tue Feb 03, 2015 2:08 am, edited 1 time in total.

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Using Image Areas

Post by SparkOut » Tue Feb 03, 2015 12:07 am

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.

Post Reply