FabPaintLib and bBrowser

This forum is meant for questions and discussions about the X# language and tools
Post Reply
alex_schmitt
Posts: 85
Joined: Wed Jan 23, 2019 7:54 pm
Location: Germany

FabPaintLib and bBrowser

Post by alex_schmitt »

Dear all,

I have a bBrowser with a Data Column that displays pictures. In X# the behavior is different than in VO and the picure is not drawn correctly, i.e. partially cut off or scaled weirdly.
To boil down the problem I have adapted Joachim's original example from the bBrowser samples and changed the
bimgCreateBitmapFromDibString() to use FabPaintLib.
Result is, that no image is drawn at all but if I debug the GetImage Function, the object FabImage object seems to be valid.

Code: Select all

PARTIAL CLASS dtwBitmaps INHERIT _dtwBitmaps


CONSTRUCTOR(oWindow,iCtlID,oServer,uExtra)  
   SUPER(oWindow,iCtlID,oServer,uExtra)
   RETURN

METHOD GetImage_Original(oServer)  // original method from Joachim. Works fine.
	// Bild aus dem Server ermitteln
	LOCAL oImage		AS bBitmap
	LOCAL cDibData		AS STRING

	// Bild als String aus dem Server ermitteln
	cDibData := oServer:FieldGet(#IMAGE)	// stattdessen FieldGet() verwendet, bis der Fehler behoben ist.
	IF !Empty(cDibData)
		// Bild in ein Bitmap-Objekt konvertieren
		oImage := bBitmap{bimgCreateBitmapFromDibString(, cDibData)}
	ENDIF
	RETURN oImage
	
	
	
METHOD GetImage(oServer) // adapted method, does not yield any picture in the colum. File exists.
	LOCAL oFabImage AS FabPaintLib.FabPaintLib
	LOCAL cThumbnailName AS STRING

	cThumbnailName := "C:temptest.jpg"
	
	IF File(cThumbnailName) //if thumbnail is already there; just take this one
		oFabImage := FabPaintLib.FabPaintLib{cThumbnailName, SELF}
	ELSE 
		QOut("Error")
	ENDIF
	
RETURN oFabImage

METHOD PostInit() 
	// Fenster und Browser initialisieren
	LOCAL odbsServer		AS OBJECT
	LOCAL oColumn			AS bDataColumn
	LOCAL oFabImage AS FabPaintLib.FabPaintLib

	// Fenster initialisieren
	SUPER:PostInit()
	SetDeleted(TRUE)

	// Server IMAGE öffnen
	odbsServer := bDBServer{"....DataImage", TRUE, FALSE, "DBFCDX"}

	IF odbsServer:Used
		// Browser initialisieren
		SELF:oDCBrowser:EnableRowHeightVariable(TRUE)
		SELF:oDCBrowser:Use(odbsServer,, {#IMAGE_NAME})

		// Spalte IMAGE_NAME initialisieren
		oColumn := SELF:oDCBrowser:GetColumn(#IMAGE_NAME)
		IF oColumn<>NULL_OBJECT
			oColumn:Caption := "Name"
		ENDIF
        
		// Spalte IMAGE initialisieren
		oColumn := bDataColumn{SELF:oDCBrowser, odbsServer, {|Server, Owner| Owner:GetImage(Server)}, #Expression, SELF}
		
		oColumn:Caption := "Image"
		oColumn:ValType := "O"
		oColumn:Alignment := BALIGN_CENTER
		oColumn:Width := 299
		SELF:oDCBrowser:AddColumn(oColumn)
		SELF:oDCBrowser:OpenColumn(oColumn)

		// Browser aktualisieren
		SELF:oDCBrowser:Recalculate()
	ENDIF

	RETURN SELF

END CLASS
Does anybody have a similar issue and could resolve it?

An old thread indicated similar problems and that it could be related to bBrowser drawing rather than FabPaintLib:

https://groups.google.com/g/comp.lang.clipper.visual-objects/c/QFn-AI1N950
screenshot.png
screenshot.png (17.19 KiB) Viewed 913 times
Best,
Alex
alex_schmitt
Posts: 85
Joined: Wed Jan 23, 2019 7:54 pm
Location: Germany

FabPaintLib and bBrowser

Post by alex_schmitt »

Hey all,

or to put it the other way round:

Is anybody in this group using pictures in a bBrowser - not necessarily FabPaintLib-based, and is successfull in doing so?
Any hint would be super cool.
I am still stuck without major progress.

Best,
Alex
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

FabPaintLib and bBrowser

Post by ic2 »

Hello Alex,

A few remarks:

1 What is bBitmap, used in the original code?

2 What happens if you create the image object using the general .Net Bitmap class? You can then assign the width & height, so if it displays something but still with the wrong scale, you could check if changing width/height fixes it.

The general (C#) code for that would be:

Code: Select all

Bitmap bmp = new Bitmap('some.bmp');
Bitmap bmp2 = new Bitmap(bmp, bmp.Width*0.5, bmp.Height*0.5); // 50%
3 Is there a difference when you show it on a monitor with a different resolution/DPI? See

https://stackoverflow.com/questions/602 ... ry-monitor

Dick
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

FabPaintLib and bBrowser

Post by ic2 »

One more thing:

I have not used images in bBrowser except icons, but what if bBrowser requires a BLOB? The help isn't specific about this.

Then you may need to convert your bitmap and it would explain why a FabPaint object doesn't show. Here's again some C# code which is doing that:

https://stackoverflow.com/questions/113 ... ap-to-byte

Dick
alex_schmitt
Posts: 85
Joined: Wed Jan 23, 2019 7:54 pm
Location: Germany

FabPaintLib and bBrowser

Post by alex_schmitt »

Thanks for getting back, Dick.

bBitmap is just an extended VO.Bitmap:

Code: Select all

CLASS bBitmap INHERIT Bitmap

CONSTRUCTOR(uPara1, uPara2) 
	IF PCount()=0
		// mache nichts
	ELSEIF IsPtr(uPara1)
		SELF:hBitmap := uPara1
	ELSE
		SUPER(uPara1, uPara2)
	ENDIF
	RETURN 

METHOD SetHandle(hBitmap) 
	// Bitmap-Handle setzen
	IF SELF:hBitmap<>NULL_PTR
		DeleteObject(SELF:hBitmap)
	ENDIF
	SELF:hBitmap := hBitmap
	RETURN TRUE

END CLASS
I tried to use C# already before, but my reading is that

Code: Select all

Bitmap bmp = new Bitmap('some.bmp');
is System.Drawing.Bitmap whereas bBrowser would expect a VO.Bitmap.

Not sure how to make them compatible.

Haven't tried with different monitors yet and also not the BLOB idea. Will check it out, too.

Best,
Alex
User avatar
Fabrice
Posts: 459
Joined: Thu Oct 08, 2015 7:47 am
Location: France

FabPaintLib and bBrowser

Post by Fabrice »

Hi Alex,
sorry if I didn't jump in before...As I don't use, and don't have bBrowser.

Just to test/check, is it possible to have a FabPaintCtrl on the Window that you refresh every times you select another line, and draw the image there ? ... Just to be sure that FabPaint is able to draw a correct image.

Fab
XSharp Development Team
fabrice(at)xsharp.eu
alex_schmitt
Posts: 85
Joined: Wed Jan 23, 2019 7:54 pm
Location: Germany

FabPaintLib and bBrowser

Post by alex_schmitt »

Dear Fabrice, Dick,

Thanks for your further hints.

I could finally manage to successfully draw the picture by converting a System.Drawing.Bitmap into a VO.Bitmap.

Code: Select all

INTERNAL FUNCTION getVOBitmap(cFilename as STRING) AS VO.Bitmap PASCAL

	LOCAL oStream AS System.IO.MemoryStream
	LOCAL oNetBitmap AS System.Drawing.Bitmap
    
    LOCAL aImageData AS BYTE[]
	LOCAL hBitmap AS PTR    
    
    TRY
		aImageData := System.IO.File.ReadAllBytes(cFilename)
	CATCH e AS Exception
		THROW InvalidOperationException{ "Image data not readable.", e }
	END TRY
	    
	IF ( aImageData?:Length ?? 0 ) == 0
		THROW ArgumentException{ "Image data is empty." }
	ENDIF
		
	TRY
		oStream := System.IO.MemoryStream{ aImageData }
		oNetBitmap := System.Drawing.Bitmap{ oStream }
	CATCH e AS Exception
		THROW InvalidOperationException{ "Image data is broken.", e }
	END TRY
	
	hBitmap := CopyImage(oNetBitmap:GetHbitmap(), IMAGE_BITMAP, oNetBitmap:Width, oNetBitmap:Height, LR_COPYDELETEORG)

	RETURN VO.Bitmap{ hBitmap }

This solution goes without FabPaint but as long as it works I am fine :)

Best,
Alex
User avatar
Joachim Bieler
Posts: 37
Joined: Mon Aug 19, 2019 1:51 pm
Location: Germany

FabPaintLib and bBrowser

Post by Joachim Bieler »

Hi Alex,
please excuse me for getting involved so late.
Can you send me an example application with which I can reproduce the problem. Maybe I can extend the bBrowser for X# so that this problem no longer occurs.
Regards
Joachim Bieler
Post Reply