Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Extracting Graphic Images from Embedded General Fields
Message
From
11/03/1999 04:04:16
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
10/03/1999 14:51:31
Thierry Yuen
Stantec Architecture Ltd.
Calgary, Alberta, Canada
General information
Forum:
Visual FoxPro
Category:
Pictures and Image processing
Miscellaneous
Thread ID:
00195892
Message ID:
00196250
Views:
26
>Alright, I am no longer getting that erro of having too few arguments. I'm applying the code in interactive mode. Everything seems to be fine, however, when I open up the newly created bitmap file, it is blank when it should have an image. These are the steps I have been taking: (top record has an image)
>
>use "c:\test\555.dbf"
>go top
>handle=fopen("c:\test\555.fpt")
>handleout=fcreate("c:\test\test.bmp")
>=fseek(handle,599)
>=fwrite(handleout,fread(handle,65535),65535)
>=fclose(handle) and fclose(handleout)
>close data
>quit
>
>It won't let me #define in interactive mode.
>Thanks a lot for your help, Cetin.
>
>Thierry
Hi Thierry,
Pls note that I mentioned to get a copy of that record first so fpt has no clubber but just that field contents after header. If you don't do that normally an FPT holds both memo & gen fields and structured as blocks starting with 0x00 00 00 00 or 01 as block start identifiers followed by memo contents length and data itself. Top record having image doesn't mean fpt would keep it just after byte 599. It could be anywhere in FPT and also if it's edited a new copy would be even at the end of FPT (so you could even recover "edit history" for a memo or gen field with mind blowing code till a pack (memo) :)
Here is the code I use successfully :
function SaveBMP
lparameters tcTable, tcField, tnRecNo, tcOutFileName
* tcTable - Tablename containing BMP gen field
* tcField - Gen field name
* tnRecNo - recno no extract
* tcOutFileName - path and fielname of output filename except .BMP extension (no check)
local handle, handleout, lcTable
lcTable = "T"+sys(2015)
select &tcField from (tcTable) ;
	where recno() = tnRecNo ;
	into table (lcTable)
use
handle=fopen(lcTable+".fpt")
handleout=fcreate(tcOutFileName+".bmp")
lnSize = fseek(handle, 0, 2) && Seek to eof and get size
=fseek(handle,599)           && Go to start of gen file
if ( lnSize - 599 ) % 2 = 0  && Might it be a duplicate ? Let's check
     lcFirst = fread(handle, (lnSize - 599)/2) && Read first part to lcFirst
     lcSecond = fread(handle, lnSize) && Read rest to lcSecond
                                      && lnSize is totlen 
                                      && but fread() would stop at feof()
     =fwrite(handleout, lcFirst, lnSize) && Again lnSize is bigger but
                                         && correct size would be written
     if lcFirst # lcSecond      && It was not a duplicate, so write lcSecond too
        =fwrite(handleout, lcSecond, lnSize)     
     endif
else
   =fwrite(handleout, ;
              fread(handle,lnSize), ;
           lnSize)                 && Since now we have a size at hand.
                                   && So let's do readwrite in one pass 
endif
=fclose(handle)
=fclose(handleout)
erase (lcTable+".*")
Since this code doesn't do extra check for contents and extension, it's assumed that you are responsible for giving correct data for a BMP. MS doesn't say it and I didn't tested but IMHO this routine with some modification could be used as "copy general" for any general data type (I wonder why FP folks didn't do it when they have all the data of structure in first place and it wouldn't be much different from "copy memo"). For batch processing I would add another field as FileType, create a bmp directory (say mybmps) and :
scan for FileType = "BMP"
 =SaveBMP(alias(), "mygenfield", recno(), "myBMPs\"+ltrim(str(recno())) )
endscan
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform