Uploading photo from library and storing in the iPhone app.

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
chrisbailey
Posts: 10
Joined: Fri Feb 07, 2014 10:57 am

Uploading photo from library and storing in the iPhone app.

Post by chrisbailey » Mon Feb 24, 2014 3:02 pm

Hi,

I am having some trouble figuring out how to store a photo within the app on an iPhone after it has been uploaded from the photo library.

What I am trying to do is upload an image to an app as a thumbnail size (this I have managed to do). However what I would then like to do is have that image enlarge to full screen when it is pressed and remain in the app after it has been shut down.

Any help would be extremely grateful.

Many thanks
Chris

splash21
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 369
Joined: Sun Dec 19, 2010 1:10 am
Location: UK
Contact:

Re: Uploading photo from library and storing in the iPhone a

Post by splash21 » Mon Feb 24, 2014 6:28 pm

Hi, Chris.
What I am trying to do is upload an image to an app as a thumbnail size
Are you uploading the image to a server to download on other devices? Or just selecting an image from the gallery? If you need the large image, then just uploading the large image and creating the thumbnail from that as required may be the easiest way - or you could create the thumbnail from the large image and upload both - or create the thumbnail on the server!

For the app to remember the image after it's shut down, you can save app info in text files, databases, etc. I've used a few different save / load ideas in mobile apps - here's one that's really quick and works pretty well.

Code: Select all

command saveAppData
   set the folder to specialFolderPath("Documents")
   put arrayEncode(gAppA) into URL("binfile:app.cfg")
end saveAppData


command getAppData
   try
      set the folder to specialFolderPath("Documents")
      put arrayDecode(URL("binfile:app.cfg")) into gAppA
   catch tError
   end try
end getAppData
Global app data is stored in a global array - gAppA. Once an image is selected, you could;

Code: Select all

put tImageName into gAppA["SavedImage"]
saveAppData
When the app starts the next time, you can read the saved data back into the global array and do whatever needs done with it;

Code: Select all

getAppData
answer "Saved image = " & gAppA["SavedImage"]

HTH :D
LiveCode Development & Training : http://splash21.com

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Uploading photo from library and storing in the iPhone a

Post by Mark » Tue Feb 25, 2014 10:39 am

Hi Chris,

Your question isn't entirely clear. You can't upload something from something and the photo library has nothing to do with up- and downloading. Also, you don't upload an image to an app. You can, however, upload an image to a server. Also, it isn't clear whether you have been able to import (as it is called) an image from the photo library. How far exactly did you get with this?

It seems you want to be able to store a picture file and keep it available between sessions. Assuming that you have created an image control "My Picture" to display the file, you can do the following:

Code: Select all

// save file
put specialFolderpath("documents") & "/picture.pic" into myPath
put the text of img "My Picture" into url ("binfile:" & myPath)

// display the picture again
put specialFolderpath("documents") & "/picture.pic" into myPath
put  url ("binfile:" & myPath) into img "My Picture"
You can put the first 2 lines into a closeStack handler and the second 2 lines into a preOpenStack handler.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9833
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Uploading photo from library and storing in the iPhone a

Post by FourthWorld » Tue Feb 25, 2014 4:43 pm

Moderation note: A duplicate of this thread in another forum section was merged here.

In the future please post a given question only once so we can keep all the replies together to help those who find this topic valuable, as recommended in the "Suggestions for Posting" section of the Forum Guidelines: http://forums.runrev.com/phpBB2/viewtop ... =4&t=18885

Thanks.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Uploading photo from library and storing in the iPhone a

Post by Klaus » Tue Feb 25, 2014 4:50 pm

Thanks Richard, "Merge topic", why didn't I discover this until now? 8)

chrisbailey
Posts: 10
Joined: Fri Feb 07, 2014 10:57 am

Re: Uploading photo from library and storing in the iPhone a

Post by chrisbailey » Fri Feb 28, 2014 11:32 am

Hi,

Thank you for the replies.

I apologise for posting the question in two separate topics.

I have been able to import and image from the iphone photo library and resize this to what ever size I decide. What I am trying to do next is store the photo in the app after everything has been closed down and be able to make the image fill the screen when it is pressed.

At present I import the photo and it shows on the screen as a thumbnail (which I have set it to do). I now want to be able to press the thumbnail and make the image fullscreen, whilst keeping it in the app.

Many thanks
Chris

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

Re: Uploading photo from library and storing in the iPhone a

Post by Simon » Fri Feb 28, 2014 11:59 am

Hi Chris,
I'm not sure where the subject line of your post comes into this, "Uploading photo..." as your questions don't seem related to uploading. Normally we talk about uploading something when we upload a file to a server.
I'm going to ignore that for now and work on the above question.

You will have to store the image in the specialFolderPath("documents") folder. Do you know how to do that?

The full screen image?
I'm guessing you are using "lock size and position" for your thumbnails, is that true?
If it is, then just unlock them.

Add more information if I have this all wrong. Which I often do :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

chrisbailey
Posts: 10
Joined: Fri Feb 07, 2014 10:57 am

Re: Uploading photo from library and storing in the iPhone a

Post by chrisbailey » Fri Feb 28, 2014 8:31 pm

Hi Simon,

Yeah it is not uploading - I am trying to import an image from my iPhone library.

So far I have created the buttons that import an image from the library using this code:

Code: Select all

on mouseUp
   set the lockloc of the templateimage to true
   set the width of the templateimage to "72"
   set the height of the templateimage to "72"
   set the left of the templateimage to "32"
   set the top of the templateimage to "135"
   mobilePickPhoto "library"
   if the result is empty then
      end if
end mouseUp
However, I can't seem to figure out how to keep the image in the app after it has closed and make the image a clickable so it becomes full size.

What I have so far is a row of 10 buttons that are set to a lockable size - these buttons all have the above code to import the photo from the iPhone library.

What I want is for all the photos that have been imported to be saved in the app at the import (72x72) size but also be able to make the image fullscreen if pressed.

Thank you for your help

Chris

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Uploading photo from library and storing in the iPhone a

Post by Mark » Fri Feb 28, 2014 8:49 pm

Chris,

As I and Simon tried to explain before, you "upload" to a server. Why do you reply "it is not uploading"? What exactly do you mean by that?

I'll have another look at your code later, if Simon isn't quicker than me ;-)

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Re: Uploading photo from library and storing in the iPhone a

Post by Simon » Fri Feb 28, 2014 8:53 pm

Hi Chris,
You'll not actually be saving the picture at thumbnail size but full size.
Here is the lesson on saving files on mobile:
http://lessons.runrev.com/s/lessons/m/4 ... -on-mobile
By setting that 72x72 you lock the image size but not the actual image, it's still the same size it always was.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

chrisbailey
Posts: 10
Joined: Fri Feb 07, 2014 10:57 am

Re: Uploading photo from library and storing in the iPhone a

Post by chrisbailey » Sat Mar 01, 2014 8:11 am

Hi Simon,

I understand that I have not used the correct terminology and this is possibly where I am getting confused.

I am not sure if the lesson you mentioned is what I need???

I have got to the stage where I am able to import a photo from the iPhone library. The import is set at 72x72 which I understand is not saved at this resolution. The only reason it is set at this size is so it is comparable with the rest of the app.

What I want to be able to achieve next is:
1. Keep the photo within the app at 72x72 when it is closed
2. Have the 72x72 photo resize to 320x568 when it is touched - not sure what I do to make this happen
3. Have an option to clear the screen of 320x568 photo and revert back to the Card with the photo set at 72x72

Thank you
Chris

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

Re: Uploading photo from library and storing in the iPhone a

Post by Simon » Sat Mar 01, 2014 8:32 am

Hi Chris,
Oh, I see, the image is on the phone so why save it again, I get it, I was thinking about the server stuff.
In the server method one would download the image and save it to a local folder. Your question is when your app opens, how to get the previously added image back into your stack without saving it into a different folder.

Is the above what you are thinking?

That one I don't know. I don't know if there is a programmable path to the gallery.
The lesson I pointed to gives you a known method of retrieving the image.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

chrisbailey
Posts: 10
Joined: Fri Feb 07, 2014 10:57 am

Re: Uploading photo from library and storing in the iPhone a

Post by chrisbailey » Sat Mar 01, 2014 8:46 am

Hi Simon,

I didn't understand what that lesson was trying to do.

I don't know what to edit as the code in the lesson is based on a text file, nor do I know where to input the code.

If I'm honest I don't know if what I am trying to do is even possible. I have created a row of buttons with a code that picks a photo from the iPhone library and resizes the photo to 72x72 (which is the same as the button)

All I want to be able to do is save the 72x72 photo within the stack and be able to resize the image to a larger size if clicked.

Basically I want it to look like the iPhone photo library - where you have thumbnails and you click each on the make the photo full screen.

Thanks
Chris

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

Re: Uploading photo from library and storing in the iPhone a

Post by Simon » Sat Mar 01, 2014 9:06 am

Hi Chris,
What you are trying to do is possible, my thoughts were that you'd save it to a know location "documents". Text file or photo doesn't matter. The lesson was to show how/where to save the file you have.
and resizes the photo to 72x72
The 72x72 image is not really an issue as you just forced an image into a smaller box, the file itself is at the resolution it was originally taken at.

Just to clear something, an app cannot save anything to itself and data must be stored elsewhere. Apps are fixed but that doesn't mean they can't change depending on what data (in a folder) they have.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”