Adding pictures

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
carel
Posts: 58
Joined: Mon Jul 29, 2013 2:49 pm

Adding pictures

Post by carel » Mon Jul 29, 2013 6:30 pm

Hi everybody, I'm new here and just started with Livecode.

My first project is going to be a program I coded in Visual Basic a few years ago. It is a Learner's License Test.

I named each picture 1.jpg, 2.jpg and so on. Each picture was linked to a question - what I did in VB was something like this:

picture = %apppath% + question_number + ".jpg"

I want to deploy this app to multiple platforms, so what would be the best and easiest way to add these pictures to my app (there are hundreds).

Thanks

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

Re: Adding pictures

Post by Simon » Mon Jul 29, 2013 8:03 pm

Hi carel,
Welcome to the forum!

Translating your VB to LC:

Code: Select all

picture = %apppath% + question_number + ".jpg"
"picture=" becomes

Code: Select all

set the filename of image "myImage"
"%apppath%"
could be a number of things as I believe in this case it was a stored variable showing the path to your images. For cross platform simplicity I would use

Code: Select all

put specialFolderPath("documents") into appPath
"question_number"
I'm guessing this is a variable holding the file name of the image, so lets just leave that.
"+"
LC uses "&" to concatenate strings
All together:

Code: Select all

set the filename of image "myImage" to appPath & "/" & question_number & ".jpg"
Check out the Dictionary for some of the terms I've used and the lessons:
http://lessons.runrev.com/

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

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

Re: Adding pictures

Post by Klaus » Tue Jul 30, 2013 10:46 am

Use parentheses, guys!

-> set the filename of image "myImage" to (appPath & "/" & question_number & ".jpg")
8-)

carel
Posts: 58
Joined: Mon Jul 29, 2013 2:49 pm

Re: Adding pictures

Post by carel » Tue Jul 30, 2013 5:02 pm

Hi, thanks for the replies.

How will my pictures be added to the correct path if it is not "in" my app - shouldn't I add the images onto a card or cards? - The only reason I mentioned the apppath + .jpg is because that is how I did it in VB. In VB it was only for Windows - so I knew where the images was - but if it is cross-platform, then the images will have to be "inside" the app.

I hope that make sense.

Thanks

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

Re: Adding pictures

Post by Klaus » Tue Jul 30, 2013 5:55 pm

Hi carel,

how do you create "apppath" on WIndows?
I'm sure we can modify it to also fit the Mac :-)

Or is "apppath" a build-in function in VB?


Best

Klaus

carel
Posts: 58
Joined: Mon Jul 29, 2013 2:49 pm

Re: Adding pictures

Post by carel » Tue Jul 30, 2013 7:35 pm

Hi Klaus,

It's been a few years ago - I don't remember exactly, but it does not matter, it was just an example.

I think I was not clear enough: By cross-platform I mean other devices like I-pad or Android - so I won't have access to the file system eg: C:\images or whatever - so I think I would have to import the pictures into my app ??

Thanks again,

Carel

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

Re: Adding pictures

Post by Simon » Tue Jul 30, 2013 8:07 pm

Hi Carel,
so I won't have access to the file system eg: C:\images or whatever
Thats why I gave you specialFolderPath("documents") it's the same on both Android and iOS.
But sure you can include the images directly in the stack, provided it doesn't make the app to big. Apple allows a max of 50 or 60 Mb apps.

Why I'd use the documents folder is it allows one to change just an image, which means you don't have to update the whole app. Constants like button icon graphics I'd include in the stack.

I think your VB script was saying the right things and can be directly translated as I have shown (with Klaus's addition).

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

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Adding pictures

Post by dave.kilroy » Wed Jul 31, 2013 8:41 am

Hi Carel

When you make a LiveCode StandAlone you can include files (and folders) to be included in with your actual app so that when installed on a target machine you could have your store of images which can be called on as Klaus explained. Each OS needs to be treated differently as regards where the images will be located and how they can be referenced (and iOS and Android do it differently again) but if you have a lot of images the most efficient way to proceed, instead of having a bloated app, is to send out your software with accompanying image files.

Kind regards

Dave
"...this is not the code you are looking for..."

carel
Posts: 58
Joined: Mon Jul 29, 2013 2:49 pm

Re: Adding pictures

Post by carel » Wed Jul 31, 2013 10:29 am

Thanks Dave - I did not know I could include the images separately.

And thanks to you too Simon.

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Adding pictures

Post by dave.kilroy » Wed Jul 31, 2013 11:06 am

Yes its amazing what you can learn on the forum (I know I have in the past, and still do of course) - BTW I do a similar thing with sending out accompanying audio files - and you can also have accompanying text files etc
"...this is not the code you are looking for..."

Post Reply