File import picture to image control

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Batninja
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 55
Joined: Sat Oct 15, 2011 9:43 am

File import picture to image control

Post by Batninja » Mon Mar 01, 2021 11:00 pm

Hi, I'm probably missing something obvious but I cannot seem to get a decent image into an image control.

Here is my code

Code: Select all

put "" into image "coverimage" of card "Editor"
   answer file "Select an image (preferably 120dpxx120px)" with tStartDirectory with type ("JPEG Images|jpg,jpeg|JPEG" & return & "PNG Images|png|PNG")
   
   if it <> "" then
      put it into theFilePath
      put URL ("file:" & theFilePath) into image "coverimage"
   else
      --no file was selected, or cancel was pressed
      beep
   end if
It all works but the image is horribly displayed with artefact lines across it. The image control is set to "Resize quality best" and the control size locked. What do I need to do to get a decent image displayed?

Do I need to put the image into a control off-screen or another card and resize it?

Thanks as usual for all help and comments gratefully received.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: File import picture to image control

Post by jmburnod » Tue Mar 02, 2021 9:25 am

Hi,
You have to use "binfile" instead "file"

Code: Select all

 put URL ("binfile:" & theFilePath) into image "coverimage"
Best regards
Jean-Marc
https://alternatic.ch

Batninja
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 55
Joined: Sat Oct 15, 2011 9:43 am

Re: File import picture to image control

Post by Batninja » Tue Mar 02, 2021 10:23 am

Thank you so much Jean-Marc, works perfectly. Love these forums and love Livecode!

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”