xImage

xImage

Postby Marcelo Roggeri » Sat Jun 29, 2019 2:11 pm

Hola buenos días, estoy queriendo guardar en una tabla de mysql en un campo blob una imagen que se encuentra en el control xImage.
El usuario puede pegar la imagen en cuestion en ese control, entonces lo que necesito es terminar la sentencia SQL que comparto a continuacion.
Code: Select all  Expand view
// El objeto oImage
....
@ 100,100 XIMAGE oImage SIZE 300,300 OF oWnd SOURCE "logo.png" // NOBORDER
                oImage:lCanPaste := .T.   // Habilita el copiar y pegar en el controñ
......

FUNCTION Guardar(oImage)
         LOCAL cSql

         cSql  := SQL;
                  INSERT INTO imagenes ( descripcion, imagen );
                  VALUES ( "prueba desde el sistema", STRTOHEX( oImage ) )
         oCn:Execute( cSql )

RETURN NIL
 

Espero haberme explicado, este ejemplo lo tengo funcionando pero desde un archivo que esta en el disco, lo que necesito es tomarlo del mismo objeto.
Saludos
Marcelo
FWH - Harbour - BCC7 - PellesC
User avatar
Marcelo Roggeri
 
Posts: 325
Joined: Sat Jul 22, 2006 9:04 pm
Location: Venado Tuerto - Santa Fe -Argentina

Re: xImage

Postby nageswaragunupudi » Sat Jun 29, 2019 3:24 pm

If you are using FWH built-in Mariadb library:

From XImage control:
Code: Select all  Expand view

oCn:Insert( "imagenes", "descripcion,imagen", { "prueba desde el sistema", BmpToStr( oImage:GetHBitmap() ) } )
 


From File on Disk:
Code: Select all  Expand view

oCn:Insert( "imagenes", "descripcion,imagen", { "prueba desde el sistema", MEMOREAD( cImageFile ) } )
 


If you are using ADO or any other library like Dolphin:
From XImage control:
Code: Select all  Expand view

cSql  := SQL;
         INSERT INTO imagenes ( descripcion, imagen );
         VALUES ( "prueba desde el sistema", BmpToStr( oImage:GetHBitmap() ) )
oCn:Execute( cSql )
 


From File on Disk:
Code: Select all  Expand view

cSql  := SQL;
         INSERT INTO imagenes ( descripcion, imagen );
         VALUES ( "prueba desde el sistema", MEMOREAD( cImageFile ) )
oCn:Execute( cSql )
 
Regards

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

Re: xImage

Postby Marcelo Roggeri » Sat Jun 29, 2019 3:53 pm

Mr. RAO muchas gracias por la explicación, probe y me dio un error
2006 MySQL server has gone away, le amplie la memoria en mysql y desaparecio el error
pero no me guarda el movimiento en la tabla.

Code: Select all  Expand view
oCn:Insert( "imagenes", "descripcion,imagen", { "prueba desde el sistema", BmpToStr( oImage:GetHBitmap() ) } )


no da error tampoco

Saludos
Marcelo
FWH - Harbour - BCC7 - PellesC
User avatar
Marcelo Roggeri
 
Posts: 325
Joined: Sat Jul 22, 2006 9:04 pm
Location: Venado Tuerto - Santa Fe -Argentina

Re: xImage

Postby nageswaragunupudi » Sun Jun 30, 2019 1:14 am

First, please try this sample as it is. This sample uses the MySql Demo server provided by FWH.

This sample demonstrates inserting directly into the table using oCn:Insert(...) syntax and also inserting into the RowSet using oRs:Append(...), if a RowSet is opened.

Please ensure that the blob field is not minblob or mediumblob. largeblob is safer. Creating tables with FWH's oCn:CreateTable(...) is safe and avoids any possible problems in future.

Image

Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oCn, oRs
   local oDlg, oFont, oBold, oImage, oBrw

   oCn   := FW_DemoDB()

   if !oCn:TableExists( "images" )
      oCn:CreateTable( "images", { { "name", "C", 20, 0 }, { "image", "m", 10, 0 } } )
   endif

   oRs   := oCn:RowSet( "images" )

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD

   DEFINE DIALOG oDlg SIZE 900,700 PIXEL TRUEPIXEL FONT oFont

   @ 20, 20 XIMAGE oImage FILE "c:\fwh\bitmaps\olga1.jpg" SIZE 300,400 OF oDlg
   oImage:lCanPaste  := .t.

   @ 20,340 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRs COLUMNS "ID", "NAME", "IMAGE" ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
      :lCanPaste        := .t.
      :Image:cDataType  := "P"
      :Image:nDataBmpAlign := AL_CENTER
      :nRowHeight       :=  100
      :nStretchCol      := 3
      //
      :CreateFromCode()
   END

   @ 450, 20 BUTTON "INSERT IMAGE INTO TABLE" SIZE 300,30 PIXEL OF oDlg FONT oBold ;
      ACTION ( ;
      oCn:Insert( "images", "name,image", { TIME(), BmpToStr( oImage:GetHBitmap() ) } ), ;
      oRs:ReQuery(), ;
      oBrw:GoBottom(), ;
      oBrw:Refresh() )

   @ 500, 20 BUTTON "INSERT IMAGE INTO ROWSET" SIZE 300,30 PIXEL OF oDlg FONT oBold ;
      ACTION ( ;
      oRs:Append( "name,image", { TIME(), BmpToStr( oImage:GetHBitmap() ) } ), ;
      oBrw:Refresh() )

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont, oBold

   oRs:Close()
   oCn:Close()

return nil

//----------------------------------------------------------------------------//
 


Step-1: Please copy this sample to \fwh\samples folder. Change image file path "c:\fwh\bitmaps\olga1.jpg" to your fwh path, if necessary.
Build with buildh.bat or buildx.bat.

Step-2: Change oCn := FW_DemoDB() with your connection to your server and try again.

Step-3: Please check for differences between your "imagen" table and this "images" table and the exact code you have used in your program.
Regards

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

Re: xImage

Postby Marcelo Roggeri » Sun Jun 30, 2019 12:51 pm

Mr. Rao efectivamente ese ejemplo funciona, lo adapte en forma local y también. La diferencia es que la tabla la había creado a mano no por código.
Solo me queda saber como incrustar la foto desde la tabla al control xImage.
Saludos y gracias por el ejemplo y tomarse el tiempo
Marcelo
FWH - Harbour - BCC7 - PellesC
User avatar
Marcelo Roggeri
 
Posts: 325
Joined: Sat Jul 22, 2006 9:04 pm
Location: Venado Tuerto - Santa Fe -Argentina

Re: xImage

Postby Marcelo Roggeri » Sun Jun 30, 2019 1:22 pm

ya esta Mr. Rao revisando la clase encontre el metodo SetSource()

Code: Select all  Expand view
:bChange := {||  oImage:SetSource( oRs:IMAGE )   }


Muchas gracias
Marcelo
FWH - Harbour - BCC7 - PellesC
User avatar
Marcelo Roggeri
 
Posts: 325
Joined: Sat Jul 22, 2006 9:04 pm
Location: Venado Tuerto - Santa Fe -Argentina

Re: xImage

Postby Marcelo Roggeri » Sun Jun 30, 2019 2:00 pm

Mr. Rao
Sobre el ejemplo suyo todo bien, pero en mi codigo no se por que no me lo guarda.
Adjunto el codigo
Code: Select all  Expand view
#include "FiveWin.ch"
#include "xbrowse.ch"
#include "adodef.ch"    // IMPORTANT

STATIC oCn, oRs
****************************************************************************
*
FUNCTION MAIN()
         LOCAL oWnd, oBar

         FWCONNECT oCn HOST "localhost" USER "root" PASSWORD "1234" DB "fwh"

         if !oCn:TableExists( "imagenes" )
            oCn:CreateTable( "imagenes", { { "name",  "C", 20, 0 },;
                                           { "foto",  "m", 10, 0 } } )
         endif

         oRs   := oCn:RowSet( "imagenes" )

         DEFINE WINDOW oWnd

            DEFINE BUTTONBAR oBar SIZE 100,50 OF oWnd 2007

                       DEFINE BUTTON PROMPT "Fotos" GROUP OF oBar;
                              FILE "C:\FWH\BITMAPS\32x32\image.bmp";
                      ACTION DlgImage()

                       DEFINE BUTTON PROMPT "Salir" GROUP OF oBar;
                              FILE "C:\FWH\BITMAPS\32x32\quit.bmp";
                              ACTION oWnd:end()

                DEFINE MESSAGE BAR OF oWnd PROMPT "xImage DB" CENTERED

         ACTIVATE WINDOW oWnd CENTERED MAXIMIZED

RETURN NIL
*
****************************************************************************
*
Function DlgImage()
         LOCAL oDlg, oBrw, oImage

         DEFINE DIALOG oDlg SIZE 1200,700 PIXEL TRUEPIXEL

                @ 0,0 XIMAGE oImage SIZE 300,300 OF oDlg SOURCE "logoSam.png" // NOBORDER
                oImage:lCanPaste := .T.

                @ 450, 20 BUTTON "Guardar" SIZE 300,30 PIXEL OF oDlg;
                          ACTION Guardar(oImage)

                @ 0,400 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg;
                        DATASOURCE oRs COLUMNS "id", "name", "foto";
                        CELL LINES NOBORDER

                WITH OBJECT oBrw
                     :lCanPaste          := .t.
                     :foto:cDataType     := "P"
                     :foto:nDataBmpAlign := AL_CENTER
                     :nRowHeight         :=  100
                     :nStretchCol        := 3
                     :CreateFromCode()
                END

         ACTIVATE DIALOG oDlg CENTERED

RETURN NIL
*
****************************************************************************
*
FUNCTION Guardar(oImage)

         oCn:Insert( "imagenes", "name,foto", { "Nombre de la Foto", BmpToStr( oImage:GetHBitmap() ) } )
         oRs:ReQuery()

RETURN NIL
*
****************************************************************************
*

No logro entender el porque no me funciona
Saludos
Marcelo
FWH - Harbour - BCC7 - PellesC
User avatar
Marcelo Roggeri
 
Posts: 325
Joined: Sat Jul 22, 2006 9:04 pm
Location: Venado Tuerto - Santa Fe -Argentina

Re: xImage

Postby nageswaragunupudi » Sun Jun 30, 2019 2:31 pm

After oRs:Requery(),
add
oBrw:GoBottom()
oBrw:Refresh()
Regards

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


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 99 guests