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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving BMP in GEN Field to File 1

Status
Not open for further replies.

Brak

Programmer
Jul 11, 2001
158
US
Ok, importnat question.

I have saved BMPs into a DBF as a GEN field.
I did so using the APPEN GEN command.

After doing so I notived that the file was double the size of the individual files combined themselves. I chose the STATIC option from the menu which brought the file back down to the size it should have been (appro the same as the combined value of the images.

Now I would like to retrieve the images back into a file. How do I do this. The only way I see is to open the Gen filed select it do the old CTRL+C open up MS Paint and do the old CTRL+V and save it. Not a big deal for a handful of images, but I have almost 1000.

Hence I would really like a command to use in a loop, just like I did with the APPEN GEN. Something like a COPY GEN, but no such function exists - at least that I know of.

B"H
Brak
 
This problem is the reason most FoxPro experts recommend you avoid General fields. There's no generic way to get the data back out.

Tamar
 
Brak,
Here are some techniques I've "gathered" (results may differ for you!):
1) One technique to get stuff out of a general field is available at - Copy General.

2) - "HOWTO: Export an Embedded .bmp Image into a File"

3)
Code:
SELECT pictures
* Make sure the created file contains this picture only!
COPY TO &lcdbf FIELDS &pcfield &pnfor && for upper(&pcField)=upper(pcPict)
lnhandle=FOPEN(lcfile + '.fpt')
lnhandleout=FCREATE(lcfile + '.bmp')
=FSEEK(lnhandle, 599)
DO WHILE !FEOF(lnhandle)
 =FWRITE(lnhandleout, FREAD(lnhandle, 512), 512)
ENDDO
=FCLOSE(lnhandle)
=FCLOSE(lnhandleout)
Ranjan Brahma
*------

4) Another variant is by Çetin Basöz:
Code:
Function savebmps
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

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)
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+".*")
Cetin
*------

Rick
 
Lady Palm-Tree:
That is most annoying. You think there would be a way to get it out if there are plans to put it in. It's like a piggy bank you can never crack!

Mr. Bean
Thank you for all the wonderful info! I plan on checking it out. Even though I don't know if/how it will work I will give you a star for all the wonderful knowledge that you have imparted. Thanks!!!

B"H
Brak
 
Yep, it is annoying. As I said, most of us recommend not using General fields. A better solution is to save the filenames and keep the files, or save the data into a Memo(binary) (or in VFP 9, a blob) and extract it as needed.

BTW, I haven't run into too many people in the Fox community who know what my name means. Surprised me.

Tamar
 
The great thing about General fields though is that it allows Fox to disply BMPs on the screen. Don't know how to do that with a Memo field.

I'm glad you knew the meaning of your name as well. I was concerned that it might have cause a blank stare with a hovering question mark above your head. :)

I assume you know Hebrew, or did you read it in one of those Baby-Name books?


B"H
Brak
 
I tried the code given by microsoft - and it wasn't accurate.

First, the offset of 599 was wrong. Second a normal bitmap header starts with 'BM' and no where in the Gen field is that! This might be because I made all my Gen fields static to cut the size in half. So apparently the code give only works for non-static Gen fields.

So I messed around with numbers and had to manually create the proper header for the file. Also there was an change in the header dependent upon wether FoxPro used a 5 or 6 digit OLE code (Maybe it was 6 or 7). This header change would cause the white in B&W (grey scale) to be yellow, cyan, or purple. Praise God I got it to finally work - but only for B&W(grey scale)images. Color images are not working. So it looks like more tweaking will be needed for it to process color images.

Why, oh why didn't MS just provide a Gen Copy function?

B"H
Brak
 
Of course, I didn't choose my own name; my parents did. I'm one of 15 grandchildren on my father's side and every one of us has a Hebrew and/or Biblical name.

I have some Hebrew, but am not fluent by any means. I know enough that I can usually listen to the Torah reading and follow in the translation, but I'm really weak on speaking the language.

Shabbat shalom,
Tamar
 
Thank you, I hope you had a blessed Sabbath as well.

I take it from how you phrased things that you are not Jewish, but rather a Christian who practices some form/variation of Judaism.

If you so might be interested in checking out the website of a non-profit group I do volunteer work for called Truely Amazing Facts -
Since this forum is for professional FoxTalk and not theological discussions it would be great for you to contact me outside of the forum to continue such discussion - if you wish. Since the forum frowns on people providing personal information, I will not give my email address here. But if you go to the TAF website just mentioned and send them an email and request they "forward it to Brak".

I will be looking forward to chatting with you. Just as you are shocked that there was someone on the forum who knew the meaning of your name, I'm shocked that there is another "Christian who practices a form/variation of Judaism" here as well. :)


B"H
Brak
 
Ah, Baruch HaShem! I'm glad to hear that!

I'm sorry for my Goyish assumption. When you used the phrase "Hebrew and/or Biblical name" I had assumed that some of the names were Greek ones, like Timothy, etc - hence my assumption of you being a Christian. And then you mentioning following along with the Parsha I added to my assumption that you were a Christian observing some form of Judaism.

I hope my assumptions didn't offend you. :)

From a Goy who wishes he was a Jew,

B"H
Brak
 
We're way off topic here, but now I understand your misunderstanding. By "Hebrew and/or Biblical," I mean that some have names like mine that are both Hebrew and Biblical, while some have more modern Hebrew names (like my cousin, Margalete).

<<From a Goy who wishes he was a Jew>>

You know, we do let outsiders in. <s>

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top