importing pictures into a data grid

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

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

importing pictures into a data grid

Post by tyarmsteadBUSuSfT » Sat Mar 08, 2014 11:10 pm

Hello,
I am wrestling with importing a picture into a thumbnail of a data grid. The user would take a picture the app imports the view in to the app. The user then types a description and other data then saves it. The save button saves the info to a text file. Upon going to the data grid the data grid loads and displays the contents of the file. I can populate all of the text fields but not the image.
on FillInData pDataArray
set the text of field "EntryDate" of me to pDataArray["Date"]
set the text of field "lon" of me to pDataArray["Ion"]
set the text of field "lat" of me to pDataArray["lat"]
set the text of field "Category" of me to pDataArray["category"]
set the text of field "ItemName" of me to pDataArray["itemname"]
set the text of field "ItemDesc" of me to pDataArray["ItemDesc"]
set the hilited of button "save location" of me to (pDataArray["saveLoc"] is "true")
set the hilited of button "HIgh Rank" of me to (pDataArray["High"] is "true")
set the hilited of button "Med Rank" of me to (pDataArray["Med"] is "true")
set the hilited of button "Low Rank" of me to (pDataArray["Low"] is "true")
set the text of field "Seq Numb" of me to pDataArray["SeqNumb"]
set the text of image "itemimage"of me to pDataArray["picture"]
end FillInData
The Show Item Detail is:
on ShowItemDetail
global gSeqNumb
go to card "ItemEntry"
set itemDel to tab
put url ("file:" & specialFolderPath("documents") & "/ItemList.txt")  into tItem
repeat with x = 1 to the number of lines in tItem
if item 1 of line x of tItem is gSeqNumb then
set the text of field "ItemName" to item 2 of line x of tItem
set the text of field "itemDesc" to item 3 of line x of tItem
set the text of field "Category" to item 5 of line x of tItem
set the text of field "EntryDate" to item 4 of line x of tItem
set the text of field "lat" to item 6 of line x of tItem
set the text of field "lon" to item 7 of line x of tItem
set the text of field "ItemImage" to item 8 of line x of tItem
if item 9 of line x of tItem is "true" then
set the hilited of button "high rank" to "true"
else set the hilited of button "high rank" to "false"
if item 10 of line x of tItem is "True" then
set the hilited of button "Med rank" to "True"
else set the hilited of button "med rank" to "false"
if item 11 of line x of tItem is "True" then
set the hilited of button "low rank" to "true"
else set the hilited of button "low rank" to "false"
if item 12of line x of tItem is "True" then
set the hilited of button "save location" to "true"
else set the hilited of button "save location" to "false"
end if
end repeat
end ShowItemDetail
I am unable to get the item to display. Iv'e tried so many ways I have confused myself.
Thank you
Ty

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: importing pictures into a data grid

Post by Klaus » Sun Mar 09, 2014 12:26 am

Hi Ty,

where and how do you save the image?
set the text of image "itemimage"of me to pDataArray["picture"]
What is in pDataArray["picture"]?
Maybe you want to set the filename, if pDataArray["picture"] contains a path to the image?


Best

Klaus

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: importing pictures into a data grid

Post by tyarmsteadBUSuSfT » Sun Mar 09, 2014 4:04 pm

Klaus,
That is correct that the path name is in the pDataArray["picture"]. The test picture is saved in the documents folder.
Ty

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: importing pictures into a data grid

Post by Klaus » Sun Mar 09, 2014 4:13 pm

Hi Ty,

AHA! :D

Well, then this should do the trick:
...
set the filename of image "itemimage" of me to pDataArray["picture"]
## Optional: Adjust image dimensions...
...


Best

Klaus

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: importing pictures into a data grid

Post by tyarmsteadBUSuSfT » Sun Mar 09, 2014 5:30 pm

Klaus,
I'm using this to test:
put url ("binfile:" & specialfolderpath( "documents") & slash & "Oscar.jpg") into tImageID
then putting tImageID into the data ray, then in the fillindata script using your code, but I 'm just getting an empty image.
Ty

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: importing pictures into a data grid

Post by Klaus » Sun Mar 09, 2014 6:02 pm

Hi Ty,
tyarmsteadBUSuSfT wrote:Klaus,
That is correct that the path name is in the pDataArray["picture"]. The test picture is saved in the documents folder.
tyarmsteadBUSuSfT wrote:Klaus,
I'm using this to test:
put url ("binfile:" & specialfolderpath( "documents") & slash & "Oscar.jpg") into tImageID
then putting tImageID into the data ray, then in the fillindata script using your code, but I 'm just getting an empty image.
hm, what do you want to do:
1. set the filename or
2. put the binary image data into the image? :D

I would prefer the filename, less memory consuming, so my first proposal should work:

Code: Select all

on fillinData
  ...
  set the filename of image "itemimage" of me to pDataArray["picture"]
  ...
end fillinData
put url ("binfile:" & specialfolderpath( "documents") & slash & "Oscar.jpg") into tImageID
Here you are putting th binary image data into the variable, but later, using my cript, you set the filename!

Do this for testing with my code:
...
put specialfolderpath( "documents") & slash & "Oscar.jpg" into tImageID
...

Best

Klaus

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

Re: importing pictures into a data grid

Post by jmburnod » Sun Mar 09, 2014 6:06 pm

Hi,
Klaus suggest the filename, not files's data
What happens if you use file instead binfile.

Code: Select all

put url ("file:" & specialfolderpath( "documents") & slash & "Oscar.jpg") into tImageID
and after

Code: Select all

set the filename of image "itemimage" of me to tImageID


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

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: importing pictures into a data grid

Post by tyarmsteadBUSuSfT » Sun Mar 09, 2014 7:46 pm

Klau and Jean-Marc,
It works!! Thank you very much.
Ty

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

Re: importing pictures into a data grid

Post by jmburnod » Mon Mar 10, 2014 8:07 pm

Hi Ty,

Do you think post an exemple ?
That should be useful for others

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

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: importing pictures into a data grid

Post by tyarmsteadBUSuSfT » Mon Mar 10, 2014 11:46 pm

Sure, do you mean an example of the code?

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

Re: importing pictures into a data grid

Post by jmburnod » Tue Mar 11, 2014 1:16 pm

Hi Ty
A little stack would be better to illustrate but code is also useful :D
Best regards
https://alternatic.ch

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: importing pictures into a data grid

Post by tyarmsteadBUSuSfT » Tue May 27, 2014 2:35 am

I was going to include a stake showing how this worked, but when i recently upgraded to the version 7, now the pictures display very distoreted. Did something changed with the export images functionality?
Thanks
Ty

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: importing pictures into a data grid

Post by Klaus » Tue May 27, 2014 5:27 pm

Hi Ty,
tyarmsteadBUSuSfT wrote:I was going to include a stake showing how this worked, but when i recently upgraded to the version 7, now the pictures display very distoreted. Did something changed with the export images functionality?
no, nothing has changed so far, but all versions >= 6.7x are still DEVELOPER PREVIEWS! :D

Here a little hint about saving a lot of typing by using BOOLEan values effectively!
Instead of this:
...
if item 9 of line x of tItem is "true" then
set the hilited of button "high rank" to "true"
else set the hilited of button "high rank" to "false"
...
Do this:
...
set the hilite of button "high rank" to (item 9 of tLine = "true")
...
The engine will evaluate the expression in parens and do exactly what you want :D


Best

Klaus

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: importing pictures into a data grid

Post by tyarmsteadBUSuSfT » Tue May 27, 2014 6:19 pm

Thank for that suggestion. One last question, is there a way to go back to a previous
version of LiveCode?
Ty

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: importing pictures into a data grid

Post by Klaus » Tue May 27, 2014 6:41 pm


Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”