Saving photos
- TimStone
- Posts: 2955
- Joined: Fri Oct 07, 2005 1:45 pm
- Location: Trabuco Canyon, CA USA
- Has thanked: 25 times
- Been thanked: 2 times
- Contact:
Saving photos
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.
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
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
- Rick Lipkin
- Posts: 2669
- Joined: Fri Oct 07, 2005 1:50 pm
- Location: Columbia, South Carolina USA
Re: Saving photos
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 ..
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
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
//------------------------------
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
- TimStone
- Posts: 2955
- Joined: Fri Oct 07, 2005 1:45 pm
- Location: Trabuco Canyon, CA USA
- Has thanked: 25 times
- Been thanked: 2 times
- Contact:
Re: Saving photos
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.
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
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
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: Saving photos
Simple.
With DBF
Save images to Memo Field.
With TDatabase for DBF
or FWH MariaDB rowset for MySql
or FWH TRecSet for ADO
(identical syntax)
Save Images to BLOB field
OR
With ADO RecordSet
OR
With DBF
Save images to Memo Field.
Code: Select all | Expand
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
oTable:FileName := cFile
oTable:photo := MEMOREAD( cFile )
oTable:Save()
OR
Code: Select all | Expand
oTable:Append( "FILENAME,PHOTO", { cFile, MEMOREAD( cFile ) } )
//OR
oTable:Update( "FILENAME,PHOTO", { cFile, MEMOREAD( cFile ) } )
With ADO RecordSet
Code: Select all | Expand
oTable:FileName := cFile
oTable:photo := FW_ValToSQL( MEMOREAD( cFile ) )
oTable:Update()
OR
Code: Select all | Expand
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
G. N. Rao.
Hyderabad, India
- TimStone
- Posts: 2955
- Joined: Fri Oct 07, 2005 1:45 pm
- Location: Trabuco Canyon, CA USA
- Has thanked: 25 times
- Been thanked: 2 times
- Contact:
Re: Saving photos
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
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
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: Saving photos
We can have more than 1 memo field per DBF. Single FPT file will contain all the memos.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Marc Venken
- Posts: 1485
- Joined: Tue Jun 14, 2016 7:51 am
- Location: Belgium
Re: Saving photos
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 ))
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.08 with Harbour
Using: FWH 23.08 with Harbour
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: Saving photos
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:
You can try:
Code: Select all | Expand
XBROWSER "wwonders.dbf"
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India