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

This forum is the place to discuss issues related to ReportPro, Xs2Ado, Vo2Ado, bBrowser and other 3rd party products
Post Reply
Bernhard Mayer
Posts: 49
Joined: Thu Oct 06, 2016 3:00 pm

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

Post 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
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

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

Post 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?
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Bernhard Mayer
Posts: 49
Joined: Thu Oct 06, 2016 3:00 pm

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

Post 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
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

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

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Bernhard Mayer
Posts: 49
Joined: Thu Oct 06, 2016 3:00 pm

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

Post by Bernhard Mayer »

Hi Wolfgang!

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

BR,
Bernhard
Bernhard Mayer
Posts: 49
Joined: Thu Oct 06, 2016 3:00 pm

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

Post by Bernhard Mayer »

System.Text.Encoding.Default:GetString(ms.GetBuffer()) did the trick, now the image is shown correctly!
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

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

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Bernhard Mayer
Posts: 49
Joined: Thu Oct 06, 2016 3:00 pm

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

Post 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
Post Reply