Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Including and displaying JPG files

Status
Not open for further replies.

FoxGolfer

Programmer
Jul 30, 2002
100
0
0
US
I have researched this topic and it seems the questions/responses are several years old. This also seems to be a topic that is not used that often. I'm hoping that the many contributors have perfected a solution.
I've been asked to include a .jpg file in a table for individual records. Taking a hint from Tastrade, I added a memo field for the file location and a general field for the picture. I also tried borrowing code from Tastrade to add/delete/display the picture with no success.
TIA,
Tom
 
Hi Tom

I have a employees table with their photos. Try this code to add the .jpg file:

LOCAL cJPGFile

cJPGFile = GETFILE("jpg")

IF !EMPTY(cJPGFile)
SELECT Employees
APPEND GENERAL Photo FROM (cJPGFile) LINK
=TABLEUPDATE()
THISFORM.Refresh()
ENDIF

Best regards

Germán Restrepo
Bogotá, Colombia
 
I use a binary memo field and append the jpg into that, then when I need it I write it out to disk from that binary memo field, such as to the user's temp folder sys(2023). It's the best way I've found for holding images in a table and it doesn't suffer from the bloat that a general field will give you.

boyd.gif

 
German,
I used your code and nothing happened. The information was not appended into my table.

Craig,
I will modify my table according to your suggestion. I currently have a memo field for the file location and a general field for the picture.

Tom
 
I guess I'm not getting it. The attached code generates an error message.

LOCAL cJPGFile

cJPGFile = GETFILE("jpg")

IF !EMPTY(cJPGFile)
SELECT pinpoint
APPEND MEMO picture FROM &cJPGFile Overwrite
* APPEND GENERAL picture FROM cJPGFile LINK
= TABLEUPDATE()
THISFORM.Refresh()
ENDIF

Command contains unrecognized phrase/keyword.

Tom
 
Try:

APPEND GENERAL picture FROM (cJPGFile) LINK

That said, I recommend against using General fields. They're a pain. There's really no reason to store both the file name and the picture; store one or the other.

Tamar
 
Tom,

Is 'picture' a Memo field type or a General field type?. I think 'picture' could be a VFP reserved word.

If you want to use

APPEND GENERAL mypicture FROM (cJPGFile) LINK

mypicture must be a General field type.

Germán Restrepo
Bogotá, Colombia
 
FoxGolfer,

You're close...

APPEND MEMO picture FROM (cJPGFile) Overwrite


...to get your file back out...

Copy Memo picture to (addbs(sys(2023)) + alltrim(MyTable.PicName))

...this is assuming you have a field with the name of the jpg in it. such as "MyPic.jpg". It will create the pic file in the user's temp folder... you can then do whatever you want with it... such as set an image objects picture property...

thisform.image1.picture = addbs(sys(2023)) + alltrim(MyTable.PicName)

... and then when you are done with it you can save it back into the table if there were changes made to it by the user, and/or just delete the temp pic file...

Erase (addbs(sys(2023)) + alltrim(MyTable.PicName))

boyd.gif

 
This may have an obvious answer, but if I store the jpg in a memo binary field, what control is used to display the jpg on the form? An image control, a text box, an edit box?
Thanks,
Tom
 
i have several experience in using jpeg on my program... well i use strtofile to store it to memo and filetostr to put it back in a file.. i use an image control in a form to view it..
first i extract the image to a file from the memo and make the image control to view it..

the big problems came when u want to view the picture in a report.. i can't make the report to view picture correctly.. well.. i haven't find the way yet..

i suggest u just stick to a bmp file and use append general on a general field... it much.. much easier than using a Jpg file.. but ur table will bloat..
 
FoxGolfer,

You would use an Image control. In versions prior to VFP 9 you would need to write the file out to disk from the binary memo file and then set the Picture property of the image control. In VFP 9 you can set it to the binary field by using the PictureVal property of the image control, which is suited to receive binary information.

boyd.gif

 
To TiCi,
Thanks for your input.
To Craig,
Thanks you also however the client is using 7.0 and not interested in upgrading.
Tom
 
This project has been added back to my schedule. (On again, off again).
I'm wondering if there may be someone willing to "prod" me in the right direction to complete this task.
Many of the suggestions have been great but there is some contradictions in some others.

Thanks to all, especially in advance,
Tom
 
Say you have a table that you've created that contains two fields. "PictData" which is a binary memo field and "FileName" which is a charcter field with a length of say 150. Now, in order to save the JPG (or whatever file you wish to save into the table) you would issue the following commands...

Code:
lcImageFile = "C:\MyPicture.jpg" 
INSERT INTO MyTable (FileName) VALUES (JUSTFNAME(lcImageFile))
APPEND MEMO PictData FROM (lcImageFile) OVERWRITE

...Now, in order to get your file back out of the table at runtime you need to do something like the following...

Code:
COPY MEMO PictData TO (ADDBS(SYS(2023)) + ALLTRIM(MyTable.FileName))
...what this basically does is pull the binary information out of the binary memo field "PictData" and writes it to disk as MyPicture.jpg (or whatever the filename is that is saved in the FileName field). The use of SYS(2023) just makes sure the image is written into the temp directory, but you can write it to disk wherever you want or need to.

Once the JPG has been written to disk then you can use it for whatever you need... whether that be for an image control's picture property or perhaps for manipulating it in some way. If you do make changes to the image and want to save the changes back into the table then you can use code like...

Code:
lcImageFile = ADDBS(SYS(2023)) + ALLTRIM(MyTable.FileName)
APPEND MEMO PictData FROM (lcImageFile) OVERWRITE

I hope that helps, I'm not sure what more I can add to this. You may want to play around with this a little bit in the command window to see how it works... just create a cursor or table as I specified and then start trying to save and extract a jpg or other image file from it using the code I've posted here. It's a pretty straight forward process and is much better than saving the image file into a general field.


boyd.gif

SweetPotato Software Website
My Blog
 
MR. BOYD,
Thanks for your assistance. It's ironic that I received this today, the day I allotted to get back to this and make it work. I have been playing with it since we "talked" last, I have created some temp files, etc., but haven't had any success yet. I promise to let you know how I do and what, if anything, I need(ed) to do.

Thanks, again.
Tom
 
FoxGolfer, I would set up an "Image" folder in the application's directory tree, and place the JPG file in that image folder when the photo was added, and give the JPG file a name that corresponds to the unique key that is associated with that photo, (IE employee ID, Part No, etc.).

When the photo was needed, use the image path and JPG file name as the control source for the form's control.
 
Craig,
Sorry it's so soon, but:
I have a table, called test with 2 fields, filename (C100) and pictfile (M,b).
Your first suggested line;
lcImageFile = "c:\vfp70\pinpoint\pictures\kissimmee single-ply over edge.jpg" is ok, but when I get to the code;
COPY MEMO pictfile TO (ADDBS(SYS(2023)) + ALLTRIM(test.filename) produces the "command contains unrecognized phrase/keyword error message.
Same thing with;
COPY MEMO pictfile TO (ADDBS(SYS(2023)) + ALLTRIM (justfname(lcImageFile)).
BTW, there will be no changes to the image file, viewing only.

Thanks,
Tom

 
HarryB,
Thanks, I've already done that. I have a "Pictures" sub directory for the jpg images and when I get the prototype working correctly, I will be adding another field that uniquely identifies the image with the specific project.

Tom
 
I have been producing a catalogue using pictures and tables. I have research and solved 99% of the issues I originally had.

I have images of a constant width in a Foxpro report.

I have images of roughly constant width in a WORD document.

I have images in grid cells which can be sized via a button.

I have images in an HTML report.

If I can be of any assistance pls ask with your email.

Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top