Welcome, Guest
Username: Password: Remember me
This forum is the place to discuss issues related to ReportPro, Xs2Ado, Vo2Ado, bBrowser and other 3rd party products
  • Page:
  • 1

TOPIC:

ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap 06 Jul 2021 13:15 #18998

  • Bernhard Mayer


  • Posts: 38
  • 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:
    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

    Please Log in or Create an account to join the conversation.

    ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap 06 Jul 2021 17:15 #19008

    • Chris
    • Chris's Avatar


  • Posts: 2667
  • 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?
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap 07 Jul 2021 08:08 #19017

    • Bernhard Mayer


  • Posts: 38
  • 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():
    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

    Please Log in or Create an account to join the conversation.

    ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap 07 Jul 2021 08:56 #19019

    • wriedmann
    • wriedmann's Avatar


  • Posts: 2726
  • 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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap 07 Jul 2021 09:02 #19020

    • Bernhard Mayer


  • Posts: 38
  • Hi Wolfgang!

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

    BR,
    Bernhard

    Please Log in or Create an account to join the conversation.

    ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap 07 Jul 2021 09:32 #19021

    • Bernhard Mayer


  • Posts: 38
  • System.Text.Encoding.Default:GetString(ms.GetBuffer()) did the trick, now the image is shown correctly!

    Please Log in or Create an account to join the conversation.

    ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap 07 Jul 2021 11:17 #19028

    • robert
    • robert's Avatar


  • Posts: 2308
  • 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

    Please Log in or Create an account to join the conversation.

    ReportPro 2.x .NET: rpImage with System.Drawing.Bitmap 07 Jul 2021 12:37 #19033

    • Bernhard Mayer


  • Posts: 38
  • 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

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1