Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Exporting Images In General Fields
Message
General information
Forum:
Visual FoxPro
Category:
Pictures and Image processing
Miscellaneous
Thread ID:
00651172
Message ID:
00651189
Views:
13
>Is there a way to export an image from a general field to a file? I've got jpg image files in a general field and need a way of copying them to a file.

Hi, Dennis.

This function I wrote to extract BMPs from a general field, but looking at it you'd probably adapt it to do the same with JPGs. As you may see, it involves some low level manipulation of the general field's content.

Hope it helps.
*------------------------------------
* Program....: CopyGen
* Author.....: Martín Salías (with special thanks to Raymond Krauss)
* Date.......: 19/18/98
* Notes......: Replace the missing command COPY GENERAL
* Parameters.: tcTable, tcField = Table & Field
* Parameters.: tcBMPFileName = Filename to generate (if no extension supplied, BMP is assumed)
* Returns....: The lenght of the generated file (in bytes)
* See Also...:
*
lparameters tcTable, tcField, tcBMPFileName

local lnReturn, lcSaveArea

lnReturn = 0
lcSaveArea = SaveArea()

if used( tcTable )

 if tcBMPFileName $ "."
  * it came with the extension
 else
  * add the extension
  tcBMPFileName = allt( tcBMPFileName ) + ".bmp"
 endif

 local lcTempFile
 lcTempFile = sys(2023) + "\" + sys(3)

 select ( tcTable )
 copy next 1 to ( lcTempFile ) field ( tcField )

 lcMemoFileName = lcTempFile + ".fpt"

 if file( lcMemoFileName )

  local lnFPT, lnBMP

  lnFPT = fOpen( lcMemoFileName, 10 ) && Open the memo file
  lnBMP = fCreate( tcBMPFileName ) && Create the new image file

  if lnFPT > 0 and lnBMP > 0   && If both files are open

   local lnSize, lnPointer

   lnSize = fSeek( lnFPT, 0, 2 )  && Find the total size of the memo

   lnPointer = fSeek( lnFPT, 0 )  && Return to the beginning

   * PROBLEM, PROBLEM; fRead can't read more than 64K at once, so we have to
   * read the whole picture on 64K blocks.
   *
   local lnBytesLeft, lcReadBuffer, lnBytesToRead

   lnBytesLeft  = lnSize
   lcReadBuffer = ""

   do while lnBytesLeft > 0

    lnBytesToRead = iif( lnBytesLeft > 65535, 65535, lnBytesLeft )

    lnBytesLeft = lnBytesLeft - lnBytesToRead

    * Gets the binary data of the image
    lcReadBuffer = lcReadBuffer + fRead( lnFPT, lnBytesToRead )
   enddo

   local lnBMPStart, lcWriteBuffer

   lnBMPStart = at( 'BM', lcReadBuffer ) && find start of a BMP file

   * Put the rest of the binary data on the buffer
   lcWriteBuffer = right( lcReadBuffer, len( lcReadBuffer ) - lnBMPStart +
1 )

   lnReturn = fWrite( lnBMP, lcWriteBuffer ) && write to BMP file
  endif

  fClose( lnFPT )     && close files
  fClose( lnBMP )

  delete file ( lcTempFile + ".*" )
 endif
endif

RestArea( lcSaveArea )

return lnReturn
*-------------------------------* Fin
Previous
Reply
Map
View

Click here to load this message in the networking platform