How to deal with a snapshot?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

How to deal with a snapshot?

Post by grovecat » Sat Apr 21, 2012 3:02 am

I'm embarrassed to ask this question because I know the answer is going to be blindingly obvious, but here goes:

Having imported a snapshot (which appears on the centre of the screen), how do I then get it into a variable so I can put it into the required image areas? I have tried addressing it as "the result", "it" and "last image" but they all turn out empty.

Help ...

Don

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: How to deal with a snapshot?

Post by Dixie » Sat Apr 21, 2012 9:19 am

Don...

Never be embarrased, that's what the forum is for... to 'find out'...
I have attached a stack that makes a 'snapshot and then places it into another image object on the card.

but essentially...
set the text of image "whatever" to the text of the last image of this card
hope it helps

Dixie
Attachments
placeSnapShot.livecode.zip
(116.62 KiB) Downloaded 243 times

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Re: How to deal with a snapshot?

Post by grovecat » Sat Apr 21, 2012 11:16 am

Thanks Dixie

That's great, and I was pleased to find that the following also works:

put the text of the last image on this card into tMyPic
set the text of image "NextPicture" to tMyPic

That will make it a bit simpler to put the snapshot into images on different cards.

Cheers
Don

PS that is a nice picture

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Re: How to deal with a snapshot?

Post by grovecat » Sat Apr 21, 2012 2:17 pm

I spoke too soon. Although the code works in the IDE, the following does not work on an iPad:

on mouseUp
iPhonePickPhoto camera, 600, 450
import snapshot from rectangle "380, 200, 680, 500"
set the text of image "MyPic" to the text of the last image of this card
delete last image
end mouseUp

After execution, the picture from the camera remains on the screen and "MyPic" stays empty.

So I am still baffled. Help again please ...

Cheers
Don

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: How to deal with a snapshot?

Post by jmburnod » Sat Apr 21, 2012 3:35 pm

Hi Don,

Export the snapshot to the documents folder and set the filename of image MyPic to the path is an other way

Best regards

Jean-marc
https://alternatic.ch

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

Re: How to deal with a snapshot?

Post by Klaus » Sat Apr 21, 2012 3:51 pm

Hi Don,

see may comments.

Code: Select all

on mouseUp

   ## This will create a new image, which is the LAST at this time
   iPhonePickPhoto camera, 600, 450

   ## This will also create a new image and now THIS one is the LAST one
   import snapshot  from rectangle "380, 200, 680, 500"
   set the text of image "MyPic" to the text of the last image of this card

   ## So which image will be deleted here?
   ## Yes, the snapshot :-)
   delete last image
 end mouseUp
After execution, the picture from the camera remains on the screen and "MyPic" stays empty.
So I am still baffled. Help again please ...
See above, just add a second "delete last image" at the end and it should be ok.


Best

Klaus

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: How to deal with a snapshot?

Post by Dixie » Sat Apr 21, 2012 3:53 pm

Hi...

This stack is of iphone dimensions... I don't posses an iPad...
I think that this is the basics of what you want to do...

Code: Select all

on mouseUp
   --put the number of images of this card into imageCount
   
   set the width of the templateImage to 80
   set the height of the templateImage to 125
   set the loc of the templateImage to 74,76
   set the lockloc of the templateImage to true
   
   mobilePickPhoto "rear camera", 160,230
   
   wait 0 millisecs with messages
   set the short name of  the last image of this card to "tempImage"
   create image
   set the text of the last image of this card to image "tempImage"
   delete image "tempImage"
end mouseUp
be well

Dixie
Attachments
camera.livecode.zip
(1.8 KiB) Downloaded 240 times

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Re: How to deal with a snapshot?

Post by grovecat » Sun Apr 22, 2012 1:45 am

I'm still not having much luck. In the following code I left out the deletes so I could see what is happening:

on mouseUp
iPhonePickPhoto camera, 600, 450
import snapshot from rectangle "380, 200, 680, 500"
set the text of image "myPic" to the text of the last image of this card
end mouseUp

I see the photo and snapshot, but nothing in "myPic"

Here is a bit of background to clarify what I am trying to achieve and why.

The app has screens with various numbers of pictures, each of which acts as a button and plays an associated song when pressed. It is for use for assessment of low functioning children, and the user (my son the OT) sets up a session for a client by choosing which pictures go in particular places and the song associated with them. He wanted square images and was using album covers (which are square) for the pictures, from the camera roll via the web. The app shows a thumbnail of the picture in three places during this process, so I store the pic in a global variable then put it into the image areas. Here is the relevant code snippet:

---
iPhonePickPhoto library, tWide, tHigh
put last image into gChosenPic
delete last image
go to card gTargetCard
put gChosenPic into image gPhotoTarget
---

Now he wants to use pictures from the camera, which of course are not square, and at first I tried to use the Crop command and ran into exactly the same sort of problems as here. The forum advice was to use imageData but that did not work as required so I decided to try the snapshot method as suggested by Klaus. It turns out that you cannot simply "put" the last image from a snapshot as you can with a normal image (or in fact a cropped image), hence the foray into copying imageData and then image text following forum advice. Nothing so far has worked.

I'm sure there is something really weird about a snapshot image and I still don't know how to copy it.

Over to the gurus again ...

Thanks for all the help.

Don

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Re: How to deal with a snapshot?

Post by grovecat » Sun Apr 22, 2012 7:19 am

Dixie's script produces the required snapshot (as does my script) but leaves me with the same problem. I don't know how to copy it to other locations as it becomes the last image and I still have the difficulties described above.

Cheers
Don

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: How to deal with a snapshot?

Post by Dixie » Sun Apr 22, 2012 8:43 am

Hi Don...

I am a little confused about what the end result is that you are trying to achieve here... after reading your post, I am of a mind that there are two different operations happening here...

On the one hand you would like to be able to select an image from the photo library and place it in various locations on the screen or even on different cards...

Or you would like to be able to take a picture with the camera and then place the newly taken picture in the various locations of the screen.You also wish to have the new picture to appear in a square format rather than a rectangle.

So, are the image objects on the screen ( places where the chosen photos would appear ) already defined and you just want them to be populated with either images from the photo library and/or straight from the camera ?

Could you post a screen shot to help me understand this a little better ?

be well

Dixie

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Re: How to deal with a snapshot?

Post by grovecat » Sun Apr 22, 2012 1:03 pm

Hi Dixie

I'll try to clarify the situation. There are two users of the app -- the scenario is set up by a therapist and the final result is given to a client (or more properly a patient). So, in the setting up phase, the user chooses to set up a screen with one, two, four or eight "buttons", which display the pictures we are dealing with here, in a square format. For each button, there is a choice of whether to pick a pic from the library or take one with the camera. So we could end up with a final screen containing one, two, four or eight of these pictures, each associated with a song track. The user can also select a delay (in seconds), which is the time the track will play before pausing - and it will continue on another press. Also, there is a choice to put text on the "buttons" instead of a picture but there are no problems with that. So the final user sees a screen of "buttons" containing picture or text and can play tracks by pressing them. (Actually, the buttons can also be set to play a video instead of a song).

During the setup process, there are shown two thumbnails of a chosen pic (on different cards), plus the one on the final screen (which is also a different card and varies in size depending on the number of buttons). Up until now, I simply "put" the last image (from library or camera) into a variable, then put that variable into the three images that are each on a different card. My son (an OT) has been using images of album covers downloaded from the web and put into the camera roll, and as these are square anyway there has been no problem.

Now he wants to use pictures directly from the camera and of course they distort when squashed into a square. So I started trying to accomplish this with the crop command and ran into problems in that the last image produced by the crop command simply cannot be "put" into another image or into a variable. Advice on the forum led me to try setting an image to the imageData of the last image and again had problems, Further advice had me attempting to use the snapshot command instead - and again the same problem with the last image.

So, in a nutshell, all I want to be able to do is to (a) produce a cropped image from a pic taken with the camera or chosen from the photo library and (b) put that image into image areas on different cards.

Sorry to be so long winded but it helped me to get my thoughts in order.

If you still want screen shots from the app I can probably do that but I'll have to find out how to do it.

Cheers
Don

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: How to deal with a snapshot?

Post by Dixie » Sun Apr 22, 2012 3:02 pm

Hi Don...

For me the penny is starting to drop... getting your 'square' pictures can be done with the same script as before. Just set the width and height of the template image to a width and height that would give you a square, say '100 x 100' and take the same approach to the sizes you give to the moilePickPhoto command...

Code: Select all

on mouseUp
   --put the number of images of this card into imageCount
   
   set the width of the templateImage to 100
   set the height of the templateImage to 100
   set the loc of the templateImage to 74,76
   set the lockloc of the templateImage to true
   
   mobilePickPhoto "rear camera", 200,200
   
   wait 0 millisecs with messages
   set the short name of  the last image of this card to "tempImage"
   create image
   set the text of the last image of this card to image "tempImage"
   delete image "tempImage"
end mouseUp
So, lets see if we have solved one problem before moving on to the next...:-)

be well

Dixie
Attachments
cameraSquare.livecode.zip
(1.79 KiB) Downloaded 218 times

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7397
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: How to deal with a snapshot?

Post by jacque » Sun Apr 22, 2012 6:34 pm

If I were doing this, I'd change the approach. Whenever more than one copy of an image is required, it's useful and more efficient to show those images as icons of buttons. Another advantage here is that if a button has its lockloc set to true, the icon will be centered and automatically cropped to the dimensions of the button without you doing anything. You could save yourself a lot of work with this approach.

The overview would be:

Replace the image objects with rectangular buttons. They can have the same scripts as the images do now.

On the import card, use mobilePickPhoto to bring in an image. You don't need to copy, crop, or store it; instead, put its ID into your global. Then just hide the image. The hidden image will be available anywhere in the stack. Don't delete it until you're done with it. When your app closes, it will revert to its native state, so those images will get wiped anyway.

On your thumbnail card and the display card, set the icon of the appropriate button to the ID stored in the global. If the button's location is locked you don't need to do any size management, the engine will do it.


Edited to add: Actually, thinking about this, you don't even need the global. On your import card:

get the ID of the last img
set the icon of btn <whatever> of card <"mydisplaycd"> to it
set the icon of btn <whatever> of card <"theOtherCd"> to it
...etc for all the buttons

In other words, the icons are all set immediately after import. They will persist until you either delete the image or change the icon later.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Re: How to deal with a snapshot?

Post by grovecat » Mon Apr 23, 2012 12:36 am

Dixie, unfortunately your approach does not work for the same reason that started me on this topic. My app was already setting the iPhonePickPhoto command to a square format and that worked fine when the pic was an album cover in the library and was itself square. When I access a standard 4 x 3 picture from either the library or the camera, it always comes back as 4 x 3 even though the command specifies a square image. And placing that into a square image area cause it to be compressed laterally and therefore distorted.

I'm sorry I did not make it clear enough in my post, although I did mention the squashing problem. Anyway it looks like the button id solution is an answer, although it involves a bit more complexity in my app as noted in my response to Jacque.

Cheers

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Re: How to deal with a snapshot?

Post by grovecat » Mon Apr 23, 2012 12:47 am

Hi Jacque

The button id works brilliantly although it will take a bit of work to implement. That is because the user has the choice of putting text into a button instead of a picture. So currently I manipulate layers to accommodate that choice by bringing a text box to the top instead of the image area. And there is a transparent rectangle above that which responds to the touch. Currently there are four cards with one, two, four and eight buttons respectively.

Anyway, I think I will have separate cards for picture buttons and text buttons and the coding will end up being a lot simpler, which is a good thing.

Although this will certainly solve my problem, I'd still like to know if it is possible to use iPhonePickPhoto and get an undistorted (cropped) picture into a square image area. I've spent so many hours battling with this that it would be good to know if it can be done.

Cheers
Don

Post Reply