Importing an image

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
NullSet
Posts: 13
Joined: Fri Dec 28, 2018 12:39 am

Importing an image

Post by NullSet » Mon Mar 11, 2019 7:44 pm

Forever the newbie, I've forgotten how to import an image.

To be specific, I've got an image file saved on my hard drive. I know how to display that on a card.

I want to import the image data, so reference to an external file will not be necessary for the image to display on the card. I hope I made that clear enough.

I don't need an elaborate explanation, just the basic idea.

Thanks in advance.

Tim

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

Re: Importing an image

Post by Klaus » Mon Mar 11, 2019 7:47 pm

Hi Tim,

...
import paint from file "path/to/your/image.jpg"
...

Best

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Importing an image

Post by richmond62 » Mon Mar 11, 2019 7:53 pm

imgImport.jpg

NullSet
Posts: 13
Joined: Fri Dec 28, 2018 12:39 am

Re: Importing an image

Post by NullSet » Mon Mar 11, 2019 8:27 pm

Klaus wrote:
Mon Mar 11, 2019 7:47 pm
...
import paint from file "path/to/your/image.jpg"
...
That's the ticket! Thanka, Klaus!

Looks like the image data is stored in the image object, not the card or stack. Correct?

Is there a convenient way to save the image data in the card or stack instead? In that case, how do I reference the source in the image object?

Tim

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

Re: Importing an image

Post by Klaus » Mon Mar 11, 2019 8:38 pm

Hi Tim,
NullSet wrote:
Mon Mar 11, 2019 8:27 pm
Looks like the image data is stored in the image object, not the card or stack. Correct?
correct.
NullSet wrote:
Mon Mar 11, 2019 8:27 pm
Is there a convenient way to save the image data in the card or stack instead? In that case, how do I reference the source in the image object?
You can use a custom property of the stack to store the binary image data like:

Code: Select all

...
set the cStoredImage of this stack to url("binfile:path/to/your/image.jpg")
...
Then you can later use it like:

Code: Select all

...
put the cStoredImage of this stack into img "your image here..."
...
Best

Klaus

NullSet
Posts: 13
Joined: Fri Dec 28, 2018 12:39 am

Re: Importing an image

Post by NullSet » Mon Mar 11, 2019 8:54 pm

Klaus wrote:
Mon Mar 11, 2019 8:38 pm
You can use a custom property of the stack to store the binary image data like:
Perfect!

Tim

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

Re: Importing an image

Post by Klaus » Mon Mar 11, 2019 9:02 pm

NullSet wrote:
Mon Mar 11, 2019 8:54 pm
Klaus wrote:
Mon Mar 11, 2019 8:38 pm
You can use a custom property of the stack to store the binary image data like:
Perfect!
Yes. :D

NullSet
Posts: 13
Joined: Fri Dec 28, 2018 12:39 am

Re: Importing an image

Post by NullSet » Mon Mar 11, 2019 10:36 pm

Is there a way to script:

Code: Select all

set the cStoredImage of this stack to url("binfile:path/to/your/image.jpg")
With a dialog box to select the image file I want?

Thanks!

Tim

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

Re: Importing an image

Post by SparkOut » Mon Mar 11, 2019 10:39 pm

I would be more specific with code suggestion if not on phone keyboard here, but looking up "answer file" will give you the info you need.

NullSet
Posts: 13
Joined: Fri Dec 28, 2018 12:39 am

Re: Importing an image

Post by NullSet » Mon Mar 11, 2019 11:00 pm

SparkOut wrote:
Mon Mar 11, 2019 10:39 pm
"answer file" will give you the info you need.
I remember now! Rusty!!! Thanks SparkOut :D

Tim

Post Reply