XBrowse: how to load image data instead of image name

XBrowse: how to load image data instead of image name

Postby Enrico Maria Giordano » Fri Oct 30, 2020 2:51 pm

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
User avatar
Enrico Maria Giordano
 
Posts: 8709
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

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

Postby Rick Lipkin » Fri Oct 30, 2020 5:36 pm

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
User avatar
Rick Lipkin
 
Posts: 2663
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


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

Postby nageswaragunupudi » Sat Oct 31, 2020 1:40 pm

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
Regards

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

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

Postby Enrico Maria Giordano » Sat Oct 31, 2020 2:03 pm

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
User avatar
Enrico Maria Giordano
 
Posts: 8709
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

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

Postby nageswaragunupudi » Sat Oct 31, 2020 2:09 pm

You mean you do not want to use command syntax to create XBrowse?
Regards

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


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

Postby nageswaragunupudi » Sat Oct 31, 2020 3:43 pm

This is enough
Code: Select all  Expand view

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

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

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

Postby Enrico Maria Giordano » Sat Oct 31, 2020 10:13 pm

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
User avatar
Enrico Maria Giordano
 
Posts: 8709
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

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

Postby nageswaragunupudi » Sun Nov 01, 2020 12:56 am

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
Regards

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

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

Postby Enrico Maria Giordano » Sun Nov 01, 2020 7:53 am

Thank you! It was a problem related to a local index variable. I solved with the usual "detached local" technique.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8709
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

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

Postby Enrico Maria Giordano » Mon Nov 02, 2020 2:09 pm

I discovered that I can use bStrImage for both image name file and image binary data! :-)

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8709
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

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

Postby mauri.menabue » Tue Nov 03, 2020 7:33 am

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
User avatar
mauri.menabue
 
Posts: 155
Joined: Thu Apr 17, 2008 2:38 pm

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

Postby Enrico Maria Giordano » Tue Nov 03, 2020 8:52 am

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
User avatar
Enrico Maria Giordano
 
Posts: 8709
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

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

Postby Marc Venken » Tue Nov 03, 2020 9:15 am

// detached local

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

Is there a surplus that we do it like this ?
Last edited by Marc Venken on Tue Nov 03, 2020 9:21 am, edited 1 time in total.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Next

Return to FiveWin for Harbour/xHarbour

Who is online

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

cron