Page 1 of 2

XBrowse: how to load image data instead of image name

PostPosted: Fri Oct 30, 2020 2:51 pm
by Enrico Maria Giordano
I know that we can use bStrImage to display images on an XBrowse column. But it requires a file to work (if I understood correctly). Is there a way to load image data read from a database and display it in the browse without creating a file?

Sorry if that question has already been answered but I searched it without result.

EMG

Re: XBrowse: how to load image data instead of image name

PostPosted: Fri Oct 30, 2020 5:36 pm
by Rick Lipkin
Enrico

I believe any picture that is stored into a database is in a binary form .. and you will probably need to convert the binary back to its original state ( .jpg or .bmp ) before xBrowse can render it.. I am sure Rao can come up with a solution ..

Rick Lipkin

Re: XBrowse: how to load image data instead of image name

PostPosted: Fri Oct 30, 2020 5:44 pm
by Enrico Maria Giordano
Ok, thank you.

EMG

Re: XBrowse: how to load image data instead of image name

PostPosted: Sat Oct 31, 2020 1:40 pm
by nageswaragunupudi
You do not need to do anything at all.
If the column data is binary data and also image data, it displays the data as image by itself.

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

REQUEST DBFCDX

function Main()

   local oDlg, oBrw

   USE "C:\FWH\SAMPLES\WWONDERS" NEW VIA "DBFCDX"

   DEFINE DIALOG oDlg SIZE 800,600 PIXEL TRUEPIXEL

   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE "WWONDERS" ;
      COLUMNS "NAME", "IMAGE", "DETAILS" ;  // Can use AUTOCOLS too
      LINES NOBORDER

   WITH OBJECT oBrw
      :nRowHeight    := 100 // pixels
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED

return nil
 


Field "IMAGE" is a memo field containing image data. XBrowse detects that the data is image data and displays it as image.

Field "DETAILS" also is a memo field but containing text data. XBrowse knows that this data is to be displayed as multi-line text.

Image

So, whether the data source is DBF, ADO or any other, if the column value is image-data, xbrowse detects it and displays it as image. We do not need to do anything and please do not add any unnecessary program code.

Another situation:
Sometimes, we may store image file name in a field. Or it can be a file name containing text, image.
By default, XBrowse displays the contents of the field, i.e., the file name as text.

By setting the datatype of the column to "F" ( oCol:cDataType := "F" ), we tell the xbrowse to treat the data as file name, read the contents of the file and display the contents of the file appropriately.

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

function Main()

   local oDlg, oBrw
   local aData := { { "OLGA1", "c:\fwh\bitmaps\olga1.jpg" }, ;
                    { "SEA",   "c:\fwh\bitmaps\sea.bmp"   }  }

   DEFINE DIALOG oDlg SIZE 360,500 PIXEL TRUEPIXEL

   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE aData ;
      COLUMNS 1, 2 ;  // Can use AUTOCOLS too
      HEADERS "NAME", "IMAGE" ;
      LINES NOBORDER

   WITH OBJECT oBrw
      :aCols[ 2 ]:cDataType := "F"
      :nRowHeight           := 200 // pixels
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED

return nil
 


Image

Re: XBrowse: how to load image data instead of image name

PostPosted: Sat Oct 31, 2020 2:03 pm
by Enrico Maria Giordano
Thank you Rao, but I can't use the command syntax. How can I assign the binary data to the column?

oBrw:bStrImage = ???

or what?

EMG

Re: XBrowse: how to load image data instead of image name

PostPosted: Sat Oct 31, 2020 2:09 pm
by nageswaragunupudi
You mean you do not want to use command syntax to create XBrowse?

Re: XBrowse: how to load image data instead of image name

PostPosted: Sat Oct 31, 2020 2:29 pm
by Enrico Maria Giordano
Exactly.

EMG

Re: XBrowse: how to load image data instead of image name

PostPosted: Sat Oct 31, 2020 3:43 pm
by nageswaragunupudi
This is enough
Code: Select all  Expand view

oCol:bEditValue := { || ( cAlias )->IMAGE }
// or
oCol:bEditValue := { || oRs:Fields( "image" ):Value }
 

Re: XBrowse: how to load image data instead of image name

PostPosted: Sat Oct 31, 2020 10:13 pm
by Enrico Maria Giordano
I tried:

Code: Select all  Expand view
oCol:bEditValue := { || MemoRead( cImg ) }


but it doesn't work (it displays nothing).

What am I doing wrong?

EMG

Re: XBrowse: how to load image data instead of image name

PostPosted: Sun Nov 01, 2020 12:56 am
by nageswaragunupudi
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local aImages := { "c:\fwh\bitmaps\olga1.jpg", "c:\fwh\bitmaps\sea.bmp" }
   local oDlg, oBrw

   DEFINE DIALOG oDlg SIZE 750,600 PIXEL TRUEPIXEL

   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE aImages NOBORDER

   WITH OBJECT oBrw:AddCol()
      :cHeader    := "NAME"
      :bEditValue := { || aImages[ oBrw:nArrayAt ] }
      :nWidth     := 300
   END
   WITH OBJECT oBrw:AddCol()
      :cHeader    := "IMAGE"
      :bEditValue := { || MemoRead( aImages[ oBrw:nArrayAt ] ) }
      :nWidth     := 300
   END

   WITH OBJECT oBrw
      :nRowHeight := 200
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED

return nil


Image

Re: XBrowse: how to load image data instead of image name

PostPosted: Sun Nov 01, 2020 7:53 am
by Enrico Maria Giordano
Thank you! It was a problem related to a local index variable. I solved with the usual "detached local" technique.

EMG

Re: XBrowse: how to load image data instead of image name

PostPosted: Mon Nov 02, 2020 2:09 pm
by Enrico Maria Giordano
I discovered that I can use bStrImage for both image name file and image binary data! :-)

EMG

Re: XBrowse: how to load image data instead of image name

PostPosted: Tue Nov 03, 2020 7:33 am
by mauri.menabue
Hi Enrico

I have two questions to ask :

1 what is the "detached local" technique.
Can you post an example?

2 how store an image into a memo file.

TIA

Re: XBrowse: how to load image data instead of image name

PostPosted: Tue Nov 03, 2020 8:52 am
by Enrico Maria Giordano
mauri.menabue wrote:Hi Enrico

I have two questions to ask :

1 what is the "detached local" technique.
Can you post an example?


This is without detached local (you get an error):

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


FUNCTION MAIN()

    LOCAL oDlg

    LOCAL aVar := { SPACE( 20 ), SPACE( 20 ) }

    LOCAL i

    DEFINE DIALOG oDlg

    FOR i = 1 TO 2
        @ i, 1 GET aVar[ i ]
    NEXT

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


And this is with detached local (it works fine):

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


FUNCTION MAIN()

    LOCAL oDlg

    LOCAL aVar := { SPACE( 20 ), SPACE( 20 ) }

    LOCAL i

    DEFINE DIALOG oDlg

    FOR i = 1 TO 2
//        @ i, 1 GET aVar[ i ]
        MKGET( aVar, i )
    NEXT

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


STATIC FUNCTION MKGET( aVar, i )

    @ i, 1 GET aVar[ i ]

    RETURN NIL


mauri.menabue wrote:2 how store an image into a memo file.


REPLACE FIELD -> memofld WITH MEMOREAD( cImgFile )

EMG

Re: XBrowse: how to load image data instead of image name

PostPosted: Tue Nov 03, 2020 9:15 am
by Marc Venken
// detached local

Strange that we need a extra function to get it working ....

Is there a surplus that we do it like this ?