FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Recuperar imagen desde campo BLOB
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Recuperar imagen desde campo BLOB
Posted: Fri Mar 02, 2018 11:02 PM
Estimados

Antes usaba

Code (fw): Select all Collapse
   oBmpLoadFromStr( oImg, oEMPL:FOTO )  //Ya no funciona en la version FWH1801 (De Manuel (Mastintin))


He intentado con
Code (fw): Select all Collapse
 oImg:LoadFromMemory( oEMPL:FOTO ) //Da error Message not found: TBITMAP:LOADFROMMEMORY


Gracias por la ayuda
Saludos,



Adhemar C.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Recuperar imagen desde campo BLOB
Posted: Sat Mar 03, 2018 06:00 AM
Hope you are using TBitmap. Please do not use TImage as it requires freeimage.dll. TBitmap is highly enhanced in 18.01.

You can use any of the following to change the image:

Code (fw): Select all Collapse
oImg:Reload( oEmp1:photo )
// OR
oImg:SetBMP( oEmp1:photo )
// OR
oImg:LoadImage( oEmp1:photo ); oImg:Refresh()


You can also use TXImage.

You can use this small program to test. This test uses FWH provided MySql server in the cloud for learning purposes.
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oCn   := FW_DemoDB()
   local oRs
   local oDlg, oFont, oBrw, oImage, oGet

   MsgRun( "Reading Images Table", "PLEASE WAIT", ;
      { || oRs := oCn:RowSet( "wwonders" ) } )

    DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 900,500 PIXEL TRUEPIXEL TITLE "MYSQL IMAGES"

   @ 20,20 XBROWSE oBrw SIZE 380,280 PIXEL OF oDlg ;
      DATASOURCE oRs ;
      COLUMNS "ID", "NAME" ;
      PICTURES "999" ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
//      :bChange := { || oImage:LoadImage( oRs:Image ), oImage:Refresh(), oGet:Refresh() }  // This works
//      :bChange := { || oImage:ReLoad( oRs:Image ),, oGet:Refresh() }               // This also works
      :bChange := { || oImage:SetBMP( oRs:Image ), oGet:Refresh() } // This also works
      //
      :CreateFromCode()
   END

   @ 20,400 BITMAP oImage SIZE 480,480 PIXEL OF oDlg ;
      FILE oRs:Image

   @ 300,20 GET oGet VAR oRs:Details MEMO SIZE 380,180 PIXEL OF oDlg UPDATE

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

   oRs:Close()
   oCn:Close()

return nil




Using XImage is even much simpler:
This can be used in many previous versions of FWH.
There is really no need to use any other functions. FWH provides a very simple and straightforward usage without any external functions.
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oCn   := FW_DemoDB()
   local oRs
   local oDlg, oFont, oBrw, oImage, oGet

   MsgRun( "Reading Images Table", "PLEASE WAIT", ;
      { || oRs := oCn:RowSet( "wwonders" ) } )

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 900,500 PIXEL TRUEPIXEL TITLE "MYSQL IMAGES"

   @ 20,20 XBROWSE oBrw SIZE 380,280 PIXEL OF oDlg ;
      DATASOURCE oRs ;
      COLUMNS "ID", "NAME" ;
      PICTURES "999" ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
//      :bChange    := { || oImage:Refresh(), oGet:Refresh() } // This also works
      :bChange    := { || oDlg:Update() }    // This is a lot simpler
      //
      :CreateFromCode()
   END

   @ 20,400 XIMAGE oImage SIZE 480,480 OF oDlg ;
      SOURCE oRs:Image UPDATE

   @ 300,20 GET oGet VAR oRs:Details MEMO SIZE 380,180 PIXEL OF oDlg UPDATE

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

   oRs:Close()
   oCn:Close()

return nil
Regards



G. N. Rao.

Hyderabad, India
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Recuperar imagen desde campo BLOB
Posted: Sat Mar 03, 2018 01:39 PM

Thank you very much Mr. Rao

The OBMPLOADFROMSTR I already solved with xIMAGE.

I'm missing GPRNSAYIMAGE that allows you to print image from BLOB field, how do you do it now to avoid using freeimage.dll

Thank you so much.

Saludos,



Adhemar C.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Recuperar imagen desde campo BLOB
Posted: Sat Mar 03, 2018 02:55 PM

The OBMPLOADFROMSTR I already solved with xIMAGE.


Please note that you can easily do it with both TXImage and also TBitmap.


I'm missing GPRNSAYIMAGE that allows you to print image from BLOB field, how do you do it now to avoid using freeimage.dll


Do you want to print on a printer?
Use this command from print.ch:
Code (fw): Select all Collapse
#xcommand @ <nRow>, <nCol> PRINT TO <prn> IMAGE <img> ;
      [SIZE <nWidth> [,<nHeight>] ] ;
      [<unit: PIXEL,MM,CM,INCHES>] ;
      [<lStr: STRETCH>] ;
      [ ALPHALEVEL <nAlpha>] ;
      [<lNoTrn: NOTRANSPARENT>] ;
      [<lGray: GRAY> ] ;
      [LASTROW <lrow>] ;


This is a sample to test:
Code (fw): Select all Collapse
#include "fivewin.ch"
function Main()

   local oCn   := FW_DemoDB()
   local oRs, nRow, oPrn, oFont

   MsgRun( "Reading Images Table", "PLEASE WAIT", ;
      { || oRs := oCn:RowSet( "wwonders" ) } )

   nRow  := 1 // 1 INCH
   PRINT oPrn PREVIEW

   DEFINE FONT oFont NAME "VERDANA" SIZE 0,-20 OF oPrn
   PAGE

   oRs:GoTo( 8 )
   @ nRow,2 PRINT TO oPrn IMAGE oRs:Image SIZE 4,4 INCHES NOTRANSPARENT LASTROW nRow

   nRow  += 0.25
   @ nRow,2 PRINT TO oPrn IMAGE oRs:Image SIZE 4,4 INCHES ALPHALEVEL 128 LASTROW nRow

   nRow  += 0.2
   @ nRow,1 PRINT TO oPrn TEXT "FWH" + CRLF +  "Image Printing" + CRLF +  "Capabilities" ;
            SIZE 6,2 INCHES ALIGN "" FONT oFont
   ENDPAGE
   ENDPRINT

   RELEASE FONT oFont

   oRs:Close()
   oCn:Close()

return nil




In the command, the image can be (a) file name, (b) resource name, (c) blob, (d) hBitmap, (e) hMeta, (f) hIcon, (g) pImage, (k) Symbol, (l) FW Shape, (m) web-address of any image or (n) image info read by FW_ReadImage. Image format can be bmp, png, gif, ico, cur, jpg, emf, wmf, tif.

Row, column, width and height can be specified in inches, mm or pixels. Images are automatically resized to the dimensions specified.

Alpha printing may not be supported by all printers.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Recuperar imagen desde campo BLOB
Posted: Sat Mar 03, 2018 03:25 PM

Perfect

Thank you very much

Saludos,



Adhemar C.

Continue the discussion