Displaying an image located on local drive

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

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Displaying an image located on local drive

Post by Traxgeek » Thu Feb 28, 2013 3:34 pm

Hi,

I'm trying to display an image that resides in the '/Users/User_Name/Documents/App_Name/Images' folder on a local drive (on my Mac)...

I'm positive this worked on my windows machine but don't have that available anymore for testing... I moved across to the Mac (full-time) some weeks ago now...

I have dumped an image called 'MyImage.jpg' into the aforementioned folder and can verify that both the path and the file (at the end of that path) exist - using Mac's 'Finder'. So far, so good !

I can also verify that LC believes the file and folder exist... BUT, I can't see the image in my image control.... :(

Code: Select all

put "MyImage.jpg" into sFile
put specialfolderpath("Documents") & "/" & "App_Name" & "/Images" into sImageFilesPath
--set the defaultFolder to sImageFilesPath --Include / rem out this line makes no difference
if there is not a folder sImageFilesPath then
   answer "The folder (" & sImageFilesPath & ") does not exist"
end if
put sImageFilesPath & "/" before sFile    
if there is not a file sFile then
   answer "The file (" & sFile & ") does not exist"
end if
set the filename of image "imgMyImage" to sFile
The 'Answer...' blocks are not displayed - LC believes the folder and the file exist) so what's going wrong with the "set the filename of image... " line ???
Like I say, I'm 95% sure this worked in the Windows version of LC (but wouldn't promise). Either way I can't see why it doesn't work as it stands here.

Any help please ?

Thanks a mil.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

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

Re: Displaying an image located on local drive

Post by jmburnod » Thu Feb 28, 2013 5:49 pm

Hi Traxgeek,

I had a look at your script and nothing is wrong for me
I tested it and it work on my Mac

Best regards
Jean-marc
https://alternatic.ch

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Displaying an image located on local drive

Post by Traxgeek » Fri Mar 01, 2013 3:55 pm

Hmmm... Thanks J-M,

I have been working on this and note that if I dump 'MyImage.jpg' into the folder at the end of the path pointed to by sPath in the following line of code

Code: Select all

put the DefaultFolder into sPath
my image is displayed...

I, therefore, surmise that something different is happening with the file paths of the folder & file and set the filename of image "imgMyImage" to sFile properties...

case 1 :

Code: Select all

put "MyImage.jpg" into sFile
put specialfolderpath("Documents") & "/" & "App_Name" & "/Images" into sImageFilesPath
if there is not a folder sImageFilesPath then
   answer "The folder (" & sImageFilesPath & ") does not exist"
end if
put sImageFilesPath & "/" before sFile   
if there is not a file sFile then
   answer "The file (" & sFile & ") does not exist"
end if
and, case 2 :

Code: Select all

set the filename of image "imgMyImage" to sFile
I'm unsure as to how to find out how LiveCode is dealing with these three properties; Folder & File and FileName

This leaves me with three questions :
-1- Are they handled differently ? The folder and file names I use both EXIST as far as LC is concerned (above code) BUT when I 'SET the filename of an image to a file/path' that LC acknowledges the existence of I do not have my image displayed, neither do I receive any error / warning... :cry:
-2- Is there a way to switch between Relative and Absolute file naming conventions ? (I note you cannot simply clear / delete the 'DefaultFolder')
-3- What does LC consider to be a 'full' path - so that it doesn't prepend any naming convention I use - which as far as I'm concerned contains the full path as per specialfolderpath("Documents"). I note that the specialfolderpath("") function returns a file path starting with a '/' and not a drive letter... Is that important as far as setting the filename of an image is concerned... The dictionary states "If you specify a file without giving its full path, LiveCode looks for the file in the defaultFolder. If you specify a relative path, the defaultFolder is prepended to it to create the full path." How does it differentiate between my having included a 'full path' in my file name and no 'full path' or an invalid 'full path' ?

Arrrgh... I'm lost (again).

I'm sure this has something to do with SpecialFolderPath / DefaultFolder and absolute/relative file naming conventions but I'm lost...

Does that help shed any additional light on my problem ?

I hope you can help.

Regards.
Last edited by Traxgeek on Fri Mar 01, 2013 4:17 pm, edited 2 times in total.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

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

Re: Displaying an image located on local drive

Post by Klaus » Fri Mar 01, 2013 4:11 pm

Hi Traxgeek,

I never set "the defaultfolder" when I can have/create an absolute pathname 8) , but try this:
...
put specialfolderpath("Documents") & "/App_Name/Images/MyImage.jpg" into tScriptFile
answer file "Where is MyImage.jpg"
## Navigate to that missing JPEG file -> MyImage.jpg!
put it into tUserSelectedFile

## Now write both pathnames to the message box:
put tScriptFile & CR & tUserSelectedFile

## Let Livecode check if these pathnames are REALLY identical:
answer (tScriptFile = tUserSelectedFile)
## should give TRUE!
...
Now you can compare both filenames and check if there is a difference!
I bet there is one :D


Best

Klaus

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Displaying an image located on local drive

Post by Traxgeek » Fri Mar 01, 2013 4:12 pm

Thanks Klaus,
I'll get straight onto it !
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

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

Re: Displaying an image located on local drive

Post by Klaus » Fri Mar 01, 2013 4:25 pm

Hi Trax,

you can also check "the result" after setting the filename of an image, might also give a hint!

Code: Select all

...
set the filename of img X to ...

## the result = EMPTy on success!
if the result <> EMTPY then
  answer the result
end if
...
Best

klaus

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Displaying an image located on local drive

Post by Traxgeek » Fri Mar 01, 2013 4:29 pm

Hmmm !

They're identical. The response is 'TRUE'...

I just don't get it... but it will be something stupid I've not understood here.
To be fair in all instances of my struggling with LC over the past few months - all have been because I've been making it too hard... D'oh !
Back to the drawing board !

Oops - our responses must have crossed...
I'll try the 'Result' too...
Here's hoping...
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Displaying an image located on local drive

Post by Traxgeek » Fri Mar 01, 2013 4:33 pm

Argggh ! Nope ! The 'Result' is empty...
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

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

Re: Displaying an image located on local drive

Post by Klaus » Fri Mar 01, 2013 4:47 pm

Hmm, running out of ideas...

Did you restart Livecode and you machine?
That sometimes helps against gremlins :D

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

Re: Displaying an image located on local drive

Post by Klaus » Fri Mar 01, 2013 5:06 pm

And when you use the button in the image inspector to select that image file?
Image is shown and has the SAME filename?

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Displaying an image located on local drive

Post by Traxgeek » Fri Mar 01, 2013 5:13 pm

Hi,

OK... restarted and no real difference but...

I copied the image there from another location, I can 'see' it there (in Finder), in that I can see its name, size, properties etc BUT... upon trying opening the image in 'Preview' I note it's all screwed up...

I have copied the original 'source' image to all 'test' locations... I'm going to check the other images (the ones in the other locations / other paths)...

...and I'm back... Yep! all open but are screwed up...

I'm going to look for an original and 'working' image and use that... (I have a feeling...)

...and I'm back...

:oops: A thousand apologies... it was simply that the image was corrupt. I don't know why... But when I replace it with a known good image all works correctly !

A thousand, thousand apologies !!! LC continues to be a huge learning curve, not helped I think by my moving over to a Mac for the first time ever a few weeks ago.

I hang my head in shame ! :oops: I should have thought of this one long ago... but...

Have a great weekend.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

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

Re: Displaying an image located on local drive

Post by Klaus » Fri Mar 01, 2013 5:23 pm

Hi Trax,

don't worry, shit happens :D
Have a great weekend, too!


Best from germany

Klaus

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Displaying an image located on local drive

Post by Traxgeek » Fri Mar 01, 2013 6:00 pm

Aha - and the same thing happens again !

OK, same problem (image not displaying) but caused by me (my incorrect understanding of LC) !

What really, really happens is this :
Upon starting, my app looks for a default 'There is no image for this person' image (like a blank camera 'icon'). If it doesn't exist then it copies the image from a resources subStack to the Images folder. The subStack image is great, I can see it in LC.
I use :

Code: Select all

put the image "imgBlank" of the card "crdImages" of stack "sstkResources" into url("file:" & gsImageFilesPath & "/" & sFile)
to copy my pre-loaded 'blank image' stack file to their Images folder...

The user can then, if they want, click on the 'blank' image (which fires up a picker window) and navigate to / select the required image for that person.
If a valid image name is returned by the 'answer file' picker dialogue then the file is copied into the Images folder by :

Code: Select all

put url("file:" & sFullFilePath) into url("file:" & gsImageFilesPath & "/" & sFile)
If I go and look at the original files, they're all OK and the Mac Preview / Finder windows display them correctly... BUT, the copied images are damaged. Sure, Finder and LC has no beef with them and they're reported as being available (but 3x the original file size) but they won't physically load as an image. LC tries, reports nothing and displays nothing...

So, it's my file copy code that is WRONG !! D'Oh.

Any ideas as to why please... It kind-of happens but not properly... In the meantime I'm off looking up more examples... see if I can spot my error... use 'BIN' perhaps... ?

Thanks.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Displaying an image located on local drive

Post by Thierry » Fri Mar 01, 2013 7:20 pm

I use :

Code: Select all

put the image "imgBlank" of the card "crdImages" of stack "sstkResources" into url("file:" & gsImageFilesPath & "/" & sFile)
So, it's my file copy code that is WRONG !! D'Oh.

Thanks.[/quote]

Hi,

Change file: with binfile:, and you will feel better.

Code: Select all

put url("file:" & sFullFilePath) into url("binfile:" & gsImageFilesPath & "/" & sFile)
HTH,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Displaying an image located on local drive

Post by Traxgeek » Sat Mar 02, 2013 4:40 pm

Hi Thierry,

I'm feeling better ! Many thanks.

When dealing with images I guess it's necessary to use binfile: / replace instances file: with binfile:.

Hadn't appreciate this.

Thanks again.

Bon weekend !
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

Post Reply