Saving photos

Saving photos

Postby TimStone » Fri Mar 01, 2019 10:12 pm

A common practice in newer window programs is to save a picture with data. For example, if I have an inventory system, for each part I want to save a picture to the data record ( using DBF ). This is faster access when browsing than having links to photos.

How might I do this ? Should the picture be stored in a memo field ?

Thanks.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Saving photos

Postby Rick Lipkin » Fri Mar 01, 2019 10:46 pm

Tim

With .dbf you ll have to save it in the memo field ... .fpt .. I kinda gave up on dbf\cdx .. but here is how you do it in Sql and Ado .. don't know if it would help you ..

I will say this .. it is easier to save the file to a location on the hard drive and store that location in a field .. then just point to the file to view it .. .fpt are large enough as it is .. and will get huge if you store binary file information in them...

Here is the way I manage it with Sql and take note .. I do not allow files to be stored that are just too big. in Sql you have to use the VarBinaryMax field ..

Note the key here is the AppendChunk method ..

oRsCh:Fields("notes"):AppendChunk( VTArrayWrapper():New( 17, cBUFFER ) )



Code: Select all  Expand view

//------------------------------
Static Func _Doit( oRsProj, oRsCh, cPROJECTEID, cPath )

LOCAL cFILENAME, nSTRING, nLEN, nSTART, SAYING, nDATETIME
LOCAL nHANDLE, nBYTES, cEID, cFILE, dDATE

LOCAL cBUFFER   //cBinaryData        // <------- This is the actual data to be stored
LOCAL nBytesRead

cFILE := upper(ALLTRIM( cPATH ))     // C:\DBTMP\CHARTER.DOC
nLEN  := LEN( cFILE )

nSTART := RAT( "\", cFILE )

IF nSTART > 0
ELSE
   SAYING := "
INVALID File name or Location .. Aborting"
   MsgInfo( SAYING )
   oDLG:END()
   RETURN(.F.)
ENDIF

// get file name //
cFILENAME := SUBSTR( cPATH, nSTART+1, nLEN-nSTART )    // CHARTER.PDF

IF LEN(cFILENAME) > 35
   SAYING := "
Sorry .. the maximum length of your file"+chr(10)
   SAYING += cFILENAME+CHR(10)
   SAYING += "
is longer than 35 characters. Please re-name"+chr(10)
   SAYING += "
your file to meet the 35 max length"+chr(10)
   MsgInfo( saying )
   oDlg:end()
   RETURN(.F.)
ENDIF

// open file //
nHANDLE := FOpen( cFILE )
IF FERROR() <> 0
   SAYING := "
Error reading file "+cFILE+CHR(10)
   SAYING += "
"+STR(FERROR())+CHR(10)
   MsgInfo( SAYING )
   oDLG:END()
   RETURN(.F.)
ENDIF

// get number of bytes in file
nBYTES := FSEEK( nHANDLE, 0,2 )

// pad the buffer nBytes+1
cBUFFER := SPACE(nBYTES+1)

FSeek( nHANDLE, 0, 0 )
nBytesRead   := FRead( nHANDLE, @cBuffer, nBytes )

FClose( nHANDLE )

if nBytesRead != nBytes
   SAYING := "
nBytesRead = "+str(nBYTESREAD)+CHR(10)
   SAYING += "
nBytes     = "+str(nBYTES)+CHR(10)
   SAYING += "
Error Reading Data"+chr(10)
   MsgInfo( saying )
   oDLG:END()
   RETURN ( .F. )
endif

cEID := _GenEid()
IF cEID = "
BOGUS"
   oDlg:End()
   RETURN(.F.)
ENDIF

nDateTime := dtoc(date())+"
"+time()

oRsCh:AddNew()

oRsCh:Fields("
documenteid"):Value   := cEID
oRsCH:Fields("
projecteid"):Value    := cPROJECTEID
oRsCh:Fields("
date_imported"):Value := nDateTime
oRsCh:Fields("
imported_by"):Value   := xLOGIN
oRsCh:Fields("
datalen"):Value       := nBYTES
oRsCh:Fields("
filename"):Value      := cFILENAME
oRsCh:Fields("
notes"):AppendChunk( VTArrayWrapper():New( 17, cBUFFER ) )  // stores the binary data in the field Notes

oRsCh:Update()

SysReFresh()

SAYING := "
Bytes Read   = "+str(nBYTESREAD)+CHR(10)
SAYING += "
Bytes Stored = "+str(nBYTES)+CHR(10)
SAYING += "
 "+CHR(10)
SAYING += "
Upload Complete for file name "+cFILENAME+chr(10)
MsgInfo( saying )

oRsCh:Sort("
date_imported")
oRsCh:MoveFirst()
oRsCh:Find( "
documenteid = '"+cEID+"'" )

oDLG:END()
RETURN(.T.)



If it were me using dbf\cdx .. store the file in a separate folder and save the name of the file in a field within the .dbf. .. the only downside to that is that if your \image folder somehow gets deleted .. there go your images.

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Saving photos

Postby TimStone » Fri Mar 01, 2019 11:51 pm

Rick,

Thanks ... and that is what I do currently. However, I was thinking of essentially thumbnails that instantly display on the screen of data displayed when scrolling an xBrowse. As the record changes, all the data is displayed for editing in the upper half of the Dialog.

Tim.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Saving photos

Postby nageswaragunupudi » Sat Mar 02, 2019 3:53 am

Simple.

With DBF


Save images to Memo Field.

Code: Select all  Expand view

FIELD->FILENAME  := cFile
FIELD->PHOTO     := MEMOREAD( cFile )
 


With TDatabase for DBF
or FWH MariaDB rowset for MySql
or FWH TRecSet for ADO
(identical syntax)


Save Images to BLOB field

Code: Select all  Expand view

oTable:FileName   := cFile
oTable:photo      := MEMOREAD( cFile )
oTable:Save()
 


OR

Code: Select all  Expand view

oTable:Append( "FILENAME,PHOTO", { cFile, MEMOREAD( cFile ) } )
//OR
oTable:Update( "FILENAME,PHOTO", { cFile, MEMOREAD( cFile ) } )
 


With ADO RecordSet

Code: Select all  Expand view

oTable:FileName   := cFile
oTable:photo      := FW_ValToSQL( MEMOREAD( cFile ) )
oTable:Update()
 


OR

Code: Select all  Expand view

oTable:AddNew( { "FILENAME" ,"PHOTO" }, { cFile, FW_ValToSQL( MEMOREAD( cFile ) ) } )
//OR
oTable:Update( { "FILENAME", "PHOTO" }, { cFile, FW_ValToSQL( MEMOREAD( cFile ) ) } )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Saving photos

Postby TimStone » Mon Mar 04, 2019 10:37 pm

Can we use more than 1 memo field in a DBF file ? If so, do we create more than one .FPT file ?
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Saving photos

Postby nageswaragunupudi » Tue Mar 05, 2019 8:53 am

We can have more than 1 memo field per DBF. Single FPT file will contain all the memos.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Saving photos

Postby Marc Venken » Tue Mar 05, 2019 11:51 am

At a given moment I had a massive dbf with foto's into a memo field. The file became very big and slow down over network.

I changed to a Char. field into de dbf with a link to the picture.

I have 2 sub dirs with foto's

1. Very small tumbs
2. Printable 300 dpi versions.

For the thumbs and correct sizes, I call

nconvert -out jpeg -ratio -overwrite -resize 900 0 c:\upload\pic\*.jpg

The free program... (Now a days FW has also a conversion function)

Xbrowse is very fast in showing the tumbs, and for printing I call the 300 dpi versions.

Never problems with size or what happens when the memo file is corrupted? Rebuilding is no option ))
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1430
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Saving photos

Postby nageswaragunupudi » Tue Mar 05, 2019 2:42 pm

XBrowse on its own reduces the large images to a smaller size to fit into the cell. There is no need to create and maintain separate thumb size images.

You can try:
Code: Select all  Expand view
XBROWSER "wwonders.dbf"
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Marc Venken, Silvio.Falconi and 132 guests