xsharp.eu • ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap
Page 1 of 1

ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap

Posted: Tue Jul 06, 2021 11:15 am
by Bernhard Mayer
Dear X#'ers!

In order to get "native" QR code support for ReportPro.NET 2.x I would like to do the following:
  • Provide a delegate which holds a container variable as a param whereas the container has properties for an expression as well as a System.Drawing.Bitmap
  • At runtime the delegate should be called with the container param with the evaluated expression value.
  • In my application a QR component creates a System.Drawing.Bitmap holding the expression value.
  • Back in ReportPro rpPicture resp. rpImage will take this Bitmap and use its content to draw the image on the Report.
Currently I'm still trying to get rpImage and the underlying CAPaint DIB functions to work with System.Drawing.Bitmap.

I already tried this (Sample code from within rpImage.LoadFromFile), unfortunately without success:

Code: Select all

BEGIN USING VAR ms := System.IO.MemoryStream{}
   BEGIN USING VAR oBmp := System.Drawing.Bitmap{cFile}
      oBmp:Save(ms, System.Drawing.Imaging.ImageFormat.Png)
      RETURN SELF:LoadFromDynaString(Convert.ToBase64String(ms:GetBuffer()))
   END USING
END USING
Could anyone point me to the right direction?

BR,
Bernhard

ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap

Posted: Tue Jul 06, 2021 3:15 pm
by Chris
Hi Bernhard,

What do you mean by there's no success? Do you get a compiler/runtime error, or is it not giving results you would expect?

ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap

Posted: Wed Jul 07, 2021 6:08 am
by Bernhard Mayer
Hi Chris!

Sorry, I should have been more precise.
  • ms.GetBuffer seems to work, returns a byte[] of size 47181
  • Convert.ToBase64String(ms.GetBuffer()) returns a string with length 62908
  • This string is passed to rpImage.LoadFromDynaString
Code excerpt from rpImage.LoadFromDynaString():

Code: Select all

SELF:Destroy()
nLen := sLen(cString) // = 62908

IF (pBuffer := StringAlloc(cString))==NULL_PTR
    ThrowOutOfMemoryError()
ENDIF

SELF:pBMP := DIBCreateFromPtr(pBuffer, LONG(nLen))
IF SELF:pBMP = NULL_PTR
   // SELF:pBMP is a NULL_PTR but the CAPaint-Functions do not reveal why
   LOCAL nError AS INT
   LOCAL pMsg AS PSZ
   nError := CAPaintLastError()
   pMsg := CAPaintLastErrorMsg()
   RpExDebug.DebOut("Error in rpImage.LoadFromDynaString # " + nError:ToString() + ", " + Psz2String(pMsg))
ENDIF
DIBConvertTo24Bits(SELF:pBmp)
MemFree(pBuffer)

RETURN SELF:IsValid
Due to the SELF:pBmp = NULL_PTR the image itself does not appear on the report. I don't know whether it could be an Unicode - Ansi thing when converting the bitmap content from the memory stream to a string value.

BR,
Bernhard

ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap

Posted: Wed Jul 07, 2021 6:56 am
by wriedmann
Hi Bernhard,
PMFJI: IMHO that cannot work.
You cannot code a byte array with base64 and expect to have it work correctly.
StringAlloc() should not do any conversion to/from unicode, so it may be the best to convert the byte[] to a string with Convert.ToString( ms.GetBuffer() )
Wolfgang

ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap

Posted: Wed Jul 07, 2021 7:02 am
by Bernhard Mayer
Hi Wolfgang!

Unfortunately Convert.ToString(ms.GetBuffer()) gets me "System.Byte[]" but not the content of the byte array.

BR,
Bernhard

ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap

Posted: Wed Jul 07, 2021 7:32 am
by Bernhard Mayer
System.Text.Encoding.Default:GetString(ms.GetBuffer()) did the trick, now the image is shown correctly!

ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap

Posted: Wed Jul 07, 2021 9:17 am
by robert
Bernhard,

Does this mean you have now added a new object type to the Rp2 designer ?
Or are you doing this in a coded report ?

Robert

ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap

Posted: Wed Jul 07, 2021 10:37 am
by Bernhard Mayer
Hi Robert,

so far it was only a test whether rpImage can work with System.Drawing.Bitmap images, too. The next step will be to provide a delegate which is supposed to be calling the method responsible for the creation of QR images by passing a macro compiled string expression as QR content including the neccessary UI settings within the Report designer.

The goal is to provide ReportPro with the ability to create QR codes with custom defined content without having to create physical image files and without having the actual QR code functionality in ReportPro as there a plenty of QR components all over the virtual world (e.g. some of our localized QR codes include images within their QR code images to prove their origin).

BR,
Bernhard