Images in Livecode
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Images in Livecode
Hello.
A basic question about images in Livecode. I would like to know if I import an image into a stack as a control object
do I have to reference that image in a folder when building a standalone? or is the image hard
coded into the stack once imported a s a control object?
Thanks
Bidge
A basic question about images in Livecode. I would like to know if I import an image into a stack as a control object
do I have to reference that image in a folder when building a standalone? or is the image hard
coded into the stack once imported a s a control object?
Thanks
Bidge
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Images in Livecode
Hi Bidge
Best regards
Jean-Marc
No. You only have to do that if your image have a filename.if I import an image into a stack as a control object
do I have to reference that image in a folder when building a standalone?
Best regards
Jean-Marc
Last edited by jmburnod on Tue Jul 25, 2017 12:56 pm, edited 1 time in total.
https://alternatic.ch
Re: Images in Livecode
Thanks again Jean-Marc
Regards
Bidge
Regards
Bidge
Re: Images in Livecode
Hello again.
I have another question regarding images. I have a code that loads an image in a folder but what happens if someone tries to load a file that is not an image? How do you write this in so that it answers" This is not an image. Please choose an image"? I only want to use JPG, PNG and BMP.
The code could match the file extensions but I am not sure how to write it.
Many thanks
Bidge
I have another question regarding images. I have a code that loads an image in a folder but what happens if someone tries to load a file that is not an image? How do you write this in so that it answers" This is not an image. Please choose an image"? I only want to use JPG, PNG and BMP.
The code could match the file extensions but I am not sure how to write it.
Code: Select all
on mouseUp
answer file "CHOOSE A PHOTO"
if the result is "Cancel" then exit mouseUp
else
if it is not empty then
set the filename of image "i1" of stack "ImageArea" to it
end if
end if
Bidge
Re: Images in Livecode
Hi David,
...
answer file "Choose a photo:" with type "Jpeg, PNG, BMP|jpg,png,bmp|"
...
Best
Klaus
...
answer file "Choose a photo:" with type "Jpeg, PNG, BMP|jpg,png,bmp|"
...
Best
Klaus
Re: Images in Livecode
Hi Klaus.
That worked great thank you.
What if my code points to a folder this is supposed to contain several images to load
and there is nothing there to load? How do we help the user there?
Thanks again
Bidge
That worked great thank you.
What if my code points to a folder this is supposed to contain several images to load
and there is nothing there to load? How do we help the user there?
Code: Select all
on mouseUp
answer folder "CHOOSE AN IMAGE FOLDER"
if the result is "Cancel" then exit mouseUp
else
if it <> "" then
set the defaultfolder to it
put the files into myListOfFiles
filter myListOfFiles with "*.png"
repeat for each line myFile in myListOfFiles
import paint from file myFile into card "Images" of stack "ImageLoad"
end repeat
end if
end if
Bidge
Re: Images in Livecode
Hi David,
your approach is correct, but you will need to use FILTER several types to get your desired formats
and no need to mess around with "the defaultfolder" anymore"
And please format your scripts (JUST hit the TAB key from time to time in the editor) so they become better readable!
Best
Klaus
your approach is correct, but you will need to use FILTER several types to get your desired formats
and no need to mess around with "the defaultfolder" anymore"
And please format your scripts (JUST hit the TAB key from time to time in the editor) so they become better readable!
Code: Select all
on mouseUp
## Don't YELL at your users :-)
answer folder "Choose a folder:"
## if the result is "Cancel" then exit mouseUp
## When THE RESULT = CANCEL, IT is also EMPTY!
if it = EMPTY then
exit mouseup
end if
## I alsway avoid END IFs wherever possible!
## NEVER use IT more than neccessary!
put it into tFolder
## set the defaultfolder to it
## New syntax:
put files(tFolder) into myListOfFiles
## put the files into myListOfFiles
## Maybe there is a REGEX pattern we could usewith FILTER, but this is still a complete mistery to me :-D
put myListOfFiles into tJpegs
put myListOfFiles into tPngs
put myListOfFiles into tBmps
filter tJpegs with "*.jpg"
filter tPngs with "*.png"
filter tBmps with "*.bmp"
put tJpegs & CR & tPngs & CR & tBmps into tCompleteList
## Remove empty lines:
filter tCompleteList without EMPTY
repeat for each line myFile in tCompleteList
## import paint from file myFile into card "Images" of stack "ImageLoad"
import paint from file (tFolder & "/" & myFile)
## "import ... INTO ..." will not work, IMPORT always goes into the current card!
## But if I remember correctly we already had this one 8-)
end repeat
end mouseup
Klaus
Re: Images in Livecode
Hi Klaus.
Sorry but this code imports the files directly into my interface stack.
I was wanting to import them into a separate stack called "imageLoad".
Also I don't think I explained myself correctly but I was wanting to know
how to handle a situation where a user has selected a folder with no
images in it. Is there some way of telling them the folder contains no images?
Thanks
Bidge
Sorry but this code imports the files directly into my interface stack.
I was wanting to import them into a separate stack called "imageLoad".
Also I don't think I explained myself correctly but I was wanting to know
how to handle a situation where a user has selected a folder with no
images in it. Is there some way of telling them the folder contains no images?
Thanks
Bidge
Re: Images in Livecode
Hi David,
"import ... INTO..." is not supported in LC!
And do something for your memory capabilities! We've been there (and somewhere else) before!
http://forums.livecode.com/viewtopic.ph ... 99#p155599
Check right here at this place in the script (quite logical, innit?):
Best
Klaus
yes, didn't you read the comment in my script?bidgeeman wrote:Hi Klaus.
Sorry but this code imports the files directly into my interface stack.
I was wanting to import them into a separate stack called "imageLoad".
"import ... INTO..." is not supported in LC!
And do something for your memory capabilities! We've been there (and somewhere else) before!
http://forums.livecode.com/viewtopic.ph ... 99#p155599
Sure, use an "Answer" dialogbidgeeman wrote: Also I don't think I explained myself correctly but I was wanting to know
how to handle a situation where a user has selected a folder with no
images in it. Is there some way of telling them the folder contains no images?
Check right here at this place in the script (quite logical, innit?):
Code: Select all
...
## Remove empty lines:
filter tCompleteList without EMPTY
## No images in folder:
if tCompleteList = EMPTY then
answer "No images in this folder, idiot!"
exit to top
end if
...
Klaus
Re: Images in Livecode
I thank once again Klaus Also for the memories. I needed to study that old thread once again to understand how it works.
Regards
Bidge
Regards
Bidge
Re: Images in Livecode
Hi.
I have another image question please?
When loading an image from a folder in the same directory as the Livecode Stack,
what is the correct way of writing this in code?
This doesn't work and I don't understand why?
EDIT:
Not sure how to write the folder path so I have been storing all my images on a separate
stack and loading them when required but this is making the stack a large.
Thanks again for any help.
Bidge
I have another image question please?
When loading an image from a folder in the same directory as the Livecode Stack,
what is the correct way of writing this in code?
This doesn't work and I don't understand why?
EDIT:
Code: Select all
put "Images/crow.jpg" into image "Image1"
stack and loading them when required but this is making the stack a large.
Thanks again for any help.
Bidge
Re: Images in Livecode
Try this
Code: Select all
on mouseUp
local tMyPath
local tFile
set the itemDelimiter to "/"
put (item 1 to -2 of the effective fileName of this stack) & "/images/" into tMyPath
-- tMyPath now contains the path to your stack and sub folder images
put tMyPath & "crow.jpg" into tFile
-- tFile contains the full path to your image
put Url ("binfile:" & tFile) into image "Image1"
-- "binfile:" tell the stack that it is expecting data in binary format
end mouseUp
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
Re: Images in Livecode
Hi Andy.
Sorry I don't think I made myself clear. I just need to load an image from a "SET" images folder that ports with the standalone. I'm not sure how to load any image from this directory when the card loads?
Thanks
Bidge
Sorry I don't think I made myself clear. I just need to load an image from a "SET" images folder that ports with the standalone. I'm not sure how to load any image from this directory when the card loads?
Thanks
Bidge
Re: Images in Livecode
If I understand you correctly?
to change the directory you are going to load your images from
just change "/images/" to the name of the directory you will be using to load the images.
and
change the on mouseUp handler in the example to on openCard
to change the directory you are going to load your images from
just change "/images/" to the name of the directory you will be using to load the images.
and
change the on mouseUp handler in the example to on openCard
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
Re: Images in Livecode
Hi Andy. I though I did that and had the image directory path correct.
I have up-loaded the stack if someone please look at it and see why it is not loading the "crow.jpg" image?
It's more than likely my fault.
Many thanks
Bi9dge
I have up-loaded the stack if someone please look at it and see why it is not loading the "crow.jpg" image?
It's more than likely my fault.
Many thanks
Bi9dge
- Attachments
-
- LoadImage.zip
- Why is this not working?
- (9.93 KiB) Downloaded 164 times