Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to store an image in a table
Message
 
 
To
02/02/1999 09:51:02
Kenneth Downs
Secure Data Software, Inc.
New York, United States
General information
Forum:
Visual FoxPro
Category:
Pictures and Image processing
Miscellaneous
Thread ID:
00182906
Message ID:
00183090
Views:
23
>Ken,
>
>Nice to see you here!
>
>FWIW, I used to store images in tables and gave it up as difficult and ultimately not worthwhile. If you must, you do it like so:
>
>CREATE TABLE MyTest (cPicName C(10),gPicture G(4))
>APPEND BLANK
>REPLACE cPicName with "Test"
>APPEND GENERAL gPicture From "C:\MyPath\Test.BMP"
>
>To empty out the picture, use:
>BLANK FIELDS gPicture
>
>However, I still think it's a bad idea, merely MHO. I store paths to >pictures and access them at run-time. I've found it infinitely easier.

Actually what you are storing here is an OLE embeded object and not just the image. This can take a tremendous amount of diskspace compaired to just storing the image. To store just the image use a memo field. You have to write procedures to store and retrieve the image using low level file functions. Depending on your specific needs this may not be desirable but the approach does have its uses.
*Simple program to read image file into memo field.
*Please excuse the 5 minute got to get the image into a table code
*******************************************
*Table to store image: IMAGE
* Fields: 
*     Name  C(25)  Image file name
*     Image M      Memo field to hold image
*******************************************
use image
m.name=getfile('GIF','Select Image File')
if empty(m.name)
   return
endif
fh=fopen(m.name)
if fh<0
   wait window 'Error opening source file'
   use
   return
endif
m.image=''
do while !feof(fh)
   wrk=fread(fh,8000)
   m.image=m.image+wrk
enddo
=fclose(fh)
wrk1=alltrim(m.name)
sz=len(wrk1)
ck=rat('\',wrk1)
If ck>0
   wrk1=right(wrk1,sz-ck)  &&Get just the file name, drop the path
endif
m.name=wrk1
insert into image from memvar
use

*Now read the memo field and output to image file(s).
OUTDIR='C:\yourpath\'
USE IMAGE
SCAN
   fname=ALLTRIM(NAME)
   IF FILE(OUTDIR+fname)
      DELETE FILE (OUTDIR+fname)
   ENDIF
   fh = FCREATE(OUTDIR+fname)
   IF fh < 0     && Check for error creating file
      WAIT 'Cannot create output file'+fname WINDOW
      LOOP      
   ENDIF
   ims=IMAGE.IMAGE
   FWRITE(fh,ims)
   =FCLOSE(fh)
ENDSCAN
USE
Michael McLain
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform