Save signature BMP in DBF ?

Save signature BMP in DBF ?

Postby TimStone » Sat Oct 03, 2015 4:51 am

Working with credit card processing, from a terminal, I can get a signature returned and convert it to a .bmp.

I can create code to give it a unique ID name, and reference that in the transaction record, but I was curious if we can actually save a .bmp image in a .dbf file. At one point I heard we could do this with memo fields, but I've not tried it.

Anyone have an answer on this ? It would certainly be more convenient.

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: 2950
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Save signature BMP in DBF ?

Postby nageswaragunupudi » Sat Oct 03, 2015 5:56 am

You can save it in fpt memo field. Hope you are using dbfcdx.
We store jpegs like that.
Regards

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

Re: Save signature BMP in DBF ?

Postby TimStone » Sun Oct 04, 2015 5:28 pm

I am using DBFCDX ...with ADS generally.

Sample code ?
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: 2950
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Save signature BMP in DBF ?

Postby RAMESHBABU » Mon Oct 05, 2015 1:31 am

Mr.Tim,

This is how I manage to Store/Retrive/Display .JPG images.
Hope it will be usefull to you.

Code: Select all  Expand view  RUN

******************************************************************************
*** FUNCTION Export_Photo(nAdmn_No, cJPGFile, lPrompt) to Export a JPG     ***
***                 File of the Client into their Master Data              ***
******************************************************************************

STATIC FUNCTION ExportPhoto(nParty_Id, cJPGFile)

LOCAL lOk := .F., cPhoto

DbSelectArea("sl_mas")
OrdSetFocus("sl_code","sl_mas","sl_mas")
SEEK nParty_Id

IF FOUND()
   IF LockRecord()
      cPhoto := MEMOREAD(cJpgFile)
      REPLACE Sl_Mas->photo WITH cPhoto // Update Memo Field with Image Data
      DbUnLock()
   ENDIF
   lOk := .T.
ENDIF

RETURN lOk

******************************************************************************
*** STATIC FUNCTION LoadPhoto(oPhoto, nParty_Id, nOpt) to Load Party's     ***
***                 Photo from Party'
s Master                              ***
******************************************************************************

STATIC FUNCTION LoadPhoto(oPhoto, nParty_Id)

LOCAL  lOk := .F.

Use_File("sl_mas")
OrdSetFocus("sl_code","sl_mas","sl_mas")
SEEK sl_mas->sl_code

IF FOUND()
   IF .NOT. EMPTY(Sl_Mas->photo)
      cImageData := Sl_Mas->photo
      oPhoto:LoadFromMemory(cImageData)
      oPhoto:Refresh()
      lOk := .T.
   ELSE
      oPhoto:LoadImage("mnophoto")
   ENDIF
ELSE
   oPhoto:LoadImage("mnophoto")
ENDIF

oPhoto:Refresh()

RETURN lOk

******************************************************************************
*** STATIC FUNCTION EnlargeImg(oImage, oParent) Enlarge Image to original Size
******************************************************************************

STATIC FUNCTION EnlargeImg(oImage, oParent)

LOCAL oIcon, oEImage, cImageData := Sl_Mas->photo, nSeconds := 10

oImage:LoadFromMemory(cImageData)

DEFINE ICON oIcon RESOURCE "STUDENTS"

IF oImage:nOrigWidth >0 .AND. oImage:nOrigHeight >0 .AND. oEnlargeDlg = nil

   DEFINE DIALOG oEnlargeDlg SIZE oImage:nOrigWidth, oImage:nOrigHeight                          ;
          OF oParent COLOR CLR_BLACK, CLR_WHITE TRANSPARENT                                      ;
          TITLE "Actual Size of the Image"                                                       ;
          PIXEL ICON oIcon STYLE nOr( DS_MODALFRAME, 0x4L, WS_POPUP )

   @ 0,0  IMAGE oEImage SIZE oImage:nOrigWidth, oImage:nOrigHeight PIXEL OF oEnlargeDlg

   oEImage:LoadFromMemory(cImageData)
   oEImage:Refresh()

   oEImage:blClicked := {|| oEnlargeDlg:End(), oEnlargeDlg := nil }

   ACTIVATE DIALOG oEnlargeDlg CENTERED ON INIT ( Center2Client(oEnlargeDlg), IF( nSeconds != 0, ;
                                                  DlgTimer(oEnlargeDlg, nSeconds,oEImage),nil) )

   oEnlargeDlg = nil

ENDIF

RELEASE ICON  oIcon

RETURN nil

******************************************************************************
*** FUNCTION DlgTimer(oDlg, nSeconds ) to Display a Dialog for nSeconds    ***
******************************************************************************

STATIC FUNCTION DlgTimer( oParent, nSeconds )

LOCAL oTimer

DEFAULT nSeconds := 4

DEFINE TIMER oTimer OF oParent INTERVAL nSeconds * 1000 ;
       ACTION oParent2:End()

ACTIVATE TIMER oTimer

RETURN nil

*************
 


Regards,

-Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 626
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: Save signature BMP in DBF ?

Postby TimStone » Mon Oct 05, 2015 8:27 pm

I tried working with that but you are doing more than I am needing, and I was not able to make your code work for my simple need. Here is what I need to do:

1) When the signature is captured, it is then saved to disk as a .bmp file.
2) I want to store the content of that bitmap file into a memo field in a .dbf file
3) Later I will go to that record and I want to extract the bitmap to then use with
oPrn:SayBitMap(nRow, 50*nCsp, cSigFil,nCsp*35, nRsp*4 )
where oPrn is from the printer class, and cSigFil is the bitmap.

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: 2950
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Save signature BMP in DBF ?

Postby Gale FORd » Mon Oct 05, 2015 10:17 pm

I use a say to capture the signature (Obviously there is more code to get mouse info etc):
REDEFINE SAY oSignature ID 200 PROMPT "" OF oDlg

Then save it as bmp:
oSignature:SaveToBmp( cFile+'.bmp' )
replace ( MyDbf )->signature with memoread( cFile+'.bmp' )

Actually I convert it to jpg before storing into memo so it takes up less room.
I have this working well in my tablet container yard interchange program.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Save signature BMP in DBF ?

Postby Gale FORd » Mon Oct 05, 2015 10:24 pm

Quick print

cSigFileName := 'temp.bmp'
memowrit( cSigFileName, (MyDbf )->signature )
DEFINE IMAGE oSignature FILENAME cSigFileName
oPrinter:SayImage( nRow, 1, oSignature, nSigWidth, nSigHeight )
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Save signature BMP in DBF ?

Postby TimStone » Tue Oct 06, 2015 1:13 am

Thanks Gale. I had a bit of a problem due to a path issue, but it's all working now.
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: 2950
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Save signature BMP in DBF ?

Postby RAMESHBABU » Tue Oct 06, 2015 1:58 am

Hello Mr.Tim,

I this may be the code you are looking for.

This is an Independent test. You can compile and test it.

Code: Select all  Expand view  RUN

******************
*** SIGN.PRG
******************

#include "FiveWin.ch"
#include "xbrowse.ch"

STATIC lSaved := .F.

REQUEST DBFCDX

FUNCTION CaptureSignature()

LOCAL oDlg, oSig, oSave, oClear, oPrint, oFinish, oBrush,;
      lPaint := .F., cFile := Lower("signature.bmp"),;
      cJpgFile := "signature.jpg", hDC, oGroup, oPadBrush,;
      oImage

LOCAL aGradiate := {{1,CLR_WHITE, nRGB(188,211,175)},{1,CLR_WHITE, nRGB(188,211,175)}}

DEFINE BRUSH oPadBrush COLOR CLR_WHITE
DEFINE BRUSH oBrush GRADIENT aGradiate
DEFINE DIALOG oDlg RESOURCE "SIGN_PAD" BRUSH oBrush

DEFINE IMAGE oImage OF oDlg FILE cFile

REDEFINE SAY oSig PROMPT "" ID 101 OF oDlg COLOR CLR_BLUE, CLR_WHITE

oSig:lTransparent := .T.

REDEFINE BUTTON oSave ID 102 OF oDlg                                         ;
         PROMPT "&Save"                                                      ;
         ACTION SaveToDisk(oSig, cFile, cJpgFile)

REDEFINE BUTTON oClear ID 103 OF oDlg                                        ;
         PROMPT "&Clear"                                                     ;
         ACTION ( lPaint := .F., FillRect( hDC, GetClientRect( oSig:hWnd ),  ;
                  oPadBrush:hBrush ), oSig:Refresh(.T.) )

REDEFINE BUTTON oPrint ID 104 OF oDlg                                        ;
         PROMPT "&Print"                                                     ;
         ACTION PrintSignature()

REDEFINE BUTTON oFinish ID 105 OF oDlg                                       ;
         PROMPT "&Finish"                                                    ;
         ACTION oDlg:End()

oSig:lWantClick := .T.
oSig:bLButtonUp := { | x, y, z | DoDraw( hDC, y, x, lPaint := .F. ) }
oSig:bMMoved    := { | x, y, z | DoDraw( hDC, y, x, lPaint ) }
oSig:bLClicked  := { | x, y, z | DoDraw( hDC, y, x, lPaint := .T., .T.  ) }

ACTIVATE DIALOG oDlg CENTER                                                  ;
         ON INIT hDC := GetDC( oSig:hWnd )                                   ;
         VALID ( ReleaseDC( oSig:hWnd, hDC ), .T. )

RETURN nil

******************************************************************************
*** STATIC FUNCTION DoDraw( hDc, x, y, lPaint, lReset ) - To Draw Signature **
******************************************************************************

STATIC FUNCTION DoDraw( hDc, x, y, lPaint, lReset )

IF lReset != nil .and. lReset
   MoveTo( hDC, x, y )
ENDIF
IF ! lPaint
   MoveTo( hDC, x, y )
ELSE
   LineTo( hDc, x, y )
ENDIF

RETURN nil

**********

FUNCTION SaveToDisk(oSig, cFile, cJpgFile)

oSig:SaveToBmp( cFile )

IF FILE(cFile)
   *ShellExecute(,"OPEN", cFile,,,1)
   FIConvertImageFile( cFile, cJpgFile, 2, 70 )
   IF FILE(cJpgFile)
      *MsgInfo(cJpgFile+" is saved to Disk.")
      SaveToDbf(cJpgFile)
   ELSE
      MsgInfo(cJpgFile+" is not saved to Disk.")
   ENDIF
ELSE
   MsgInfo(cFile+" is not saved to Disk.")
ENDIF

RETURN nil

**********

FUNCTION SaveToDbf(cJpgFile)

LOCAL aStruct := {}

IF .NOT. FILE("sign.dbf")
   aStruct := {{"party_id",  "N", 5, 0},;
               {"signature", "M",10, 0}}
   DbCreate("sign.dbf",aStruct,"DBFCDX")  
ENDIF

USE sign
IF EOF()
   APPEND BLANK
ENDIF

IF RLock()
   REPLACE party_id  WITH 1,;
           signature WITH MEMOREAD(cJpgFile)
   DbUnLock()
   MsgInfo("Signature is saved to Sign.Dbf. Now Print it.")
   lSaved := .T.
ENDIF

RETURN nil

**********

FUNCTION PrintSignature()

LOCAL oPrn, cSignFile := "tempsign.jpg", cSignData

FIELD signature

CLOSE ALL
USE sign ALIAS sign VIA "DBFCDX"

IF MEMOWRIT(cSignFile,sign->signature)
   PRINT oPrn PREVIEW
         PAGE
            oPrn:SayImage(10, 10, cSignFile, 1000 , 500,,.T. )
         ENDPAGE
   ENDPRINT
ELSE
   MsgInfo("Signature TempFile not generated to Print.")
ENDIF

RETURN nil

*************
 


 
Code: Select all  Expand view  RUN

****************
*** SIGN.RC
****************

SIGN_PAD DIALOG 13, 52, 255, 140
STYLE DS_MODALFRAME | 0x4L | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Signature Pad - Draw Signature with Mouse"
FONT 8, "MS Sans Serif"
{
 GROUPBOX "Signature Pad:", 301, 7, 6, 239, 105, BS_GROUPBOX
 CONTROL "", 101, "STATIC", SS_WHITERECT | WS_CHILD | WS_VISIBLE, 15, 18, 223, 85
 PUSHBUTTON "&Save", 102, 97, 118, 35, 14
 PUSHBUTTON "&Clear", 103, 135, 118, 35, 14
 PUSHBUTTON "&Print", 104, 173, 118, 35, 14
 PUSHBUTTON "&Finish", 105, 211, 118, 35, 14
}
 


-Ramesh Babu
User avatar
RAMESHBABU
 
Posts: 626
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: Save signature BMP in DBF ?

Postby bpd2000 » Tue Oct 06, 2015 5:48 am

Thank you Rameshbabu for sharing nice code
Regards, Greetings

Try FWH. You will enjoy it's simplicity and power.!
User avatar
bpd2000
 
Posts: 153
Joined: Tue Aug 05, 2014 9:48 am
Location: India

Re: Save signature BMP in DBF ?

Postby TimStone » Tue Oct 06, 2015 5:35 pm

Ramesh,

I appreciate the code, and I'm sure others will also.

In my case, the need is far simpler, and Gale's solution works perfectly.

For credit card processing, using secure terminals, some data is returned and needs to be retained. It does not benefit a hacker because it's only relative to the transaction, not the card, or cardholder. In addition, a small image of the signature is captured on the terminal.

Previously I stored the returned information in a .dbf but I also wanted to store the signature in a memo field. As a jpg, it is less than 2K, and compresses more in the .fpt. When printing out the invoice, where the card information is shown, I simply needed to print the signature in a small space. The print class function for printing images handles this perfectly, and no manipulation of the image is necessary.

I now have this working perfectly, and it takes up little space.

For those needing more complex handling of images, your code will be very helpful. It might be good for you to start a new thread with a better Subject title so more people can see it and take advantage of the benefit.

Thank you.

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: 2950
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Save signature BMP in DBF ?

Postby RAMESHBABU » Wed Oct 07, 2015 12:10 am

Mr.Tim,

For credit card processing, using secure terminals, some data is returned and needs to be retained. It does not benefit a hacker because it's only relative to the transaction, not the card, or cardholder. In addition, a small image of the signature is captured on the terminal.


Yes, I understand and in your case Mr.Gale's solution is more than enough.

I appreciate the code, and I'm sure others will also


Thanks for your comment.

-Ramesh Babu
User avatar
RAMESHBABU
 
Posts: 626
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: Save signature BMP in DBF ?

Postby FranciscoA » Wed Oct 07, 2015 1:46 am

bpd2000 wrote:Thank you Rameshbabu for sharing nice code

+1
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2159
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 94 guests