Picture Control Throws Overflow Error when set at run time

Posted by: gphillips on 26 October 2023, 4:04 am EST

    • Post Options:
    • Link

    Posted 26 October 2023, 4:04 am EST

    I recently converted from AR12 to AR17. Things are finally working (after many challenges), but I have a problem having images come up in a report. The images are stored in a DB and set at runtime.

    When previewed with the viewer I get the following error. The error is trapped by the viewer and not by the error trap in the code.

    Exception details:
    System.OverflowException: Overflow error.
       at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
       at System.Drawing.Graphics.DrawImage(Image image, Single x, Single y, Single width, Single height)
       at System.Drawing.Graphics.DrawImage(Image image, RectangleF rect)
       at GrapeCity.ActiveReports.Core.Document.Drawing.Gdi.GdiCanvasItemRenderer.Render(CanvasItem item)
       at GrapeCity.ActiveReports.Document.Section.PageExtensions.RenderPage(Page page, Graphics graphics, Boolean printing, SmoothingMode controlsSmoothing, GdiCanvasItemRenderer renderer)
       at GrapeCity.ActiveReports.Document.Section.PageExtensions.Draw(Page page, Graphics graphics, RectangleF bounds, TextRenderingHint textRenderHint, SizeF scale, Boolean printing, DrawOptions options)
       at GrapeCity.ActiveReports.Viewer.Common.Internal..Render(Graphics graphics)
       at GrapeCity.ActiveReports.Viewer.Win.Views.MultiPageView.RenderPage(Int32 pageIndex, Graphics graphics)
    

    When the same image is used with AR12, there is no error (so it is not a data problem).

    The code changes I made are as follows:

    ' New AR 17
               Dim _ImageBytes() As Byte
    
               If _FrontEntityDocumentID > 0 Then
                   _ImageBytes = DLookup("Attachment", "tbl_EntityAttachments", "EntityDocumentID = " + _FrontEntityDocumentID.ToString)
                   Try
                       Dim _Image As GrapeCity.ActiveReports.Document.Drawing.Image
                       _Image = GrapeCity.ActiveReports.Document.Drawing.Image.FromStream(New System.IO.MemoryStream(_ImageBytes))
                       Me.Picture1.Image = _Image
                       Me.Picture1.Visible = True
                   Catch ex As Exception
                       Me.Picture1.Visible = False
                   End Try
               Else
                   Me.Picture1.Visible = False
               End If
    
    
    ' Old  AR 12
                Dim _ImageBytes() As Byte
    
                If _FrontEntityDocumentID > 0 Then
                    _ImageBytes = DLookup("Attachment", "tbl_EntityAttachments", "EntityDocumentID = " + _FrontEntityDocumentID.ToString)
                    Try
                        Dim _Image As System.Drawing.Image
                        _Image = System.Drawing.Image.FromStream(New System.IO.MemoryStream(_ImageBytes))
                        Me.Picture1.Image = _Image
                        Me.Picture1.Visible = True
                    Catch ex As Exception
                        Me.Picture1.Visible = False
                    End Try
                Else
                    Me.Picture1.Visible = False
                End If

    From the AR17 designer, the designer code for the Picture control is

            'Picture1
            '
            Me.Picture1.Height = 1.02!
            Me.Picture1.ImageBytes = Nothing
            Me.Picture1.Left = 1.566!
            Me.Picture1.Name = "Picture1"
            Me.Picture1.SizeMode = GrapeCity.ActiveReports.SectionReportModel.SizeModes.Zoom
            Me.Picture1.Top = 0.243!
            Me.Picture1.Width = 2.491!

    Any assistance would be appreciated.

  • Posted 26 October 2023, 4:11 am EST

    Follow-up: When I tried to print the report to a PDF printer, I get no error, just an empty file.

  • Posted 26 October 2023, 10:13 pm EST

    Hi,

    I could not replicate the issue on my end. The images are being rendered on the report with no issues and getting exported to the PDF too. Please refer to the attached sample that I tested with and confirm the behavior using the same. If the issue still persists, you may share your own stripped-down sample with sample data or edit the attached sample such that it reproduces the issue, and we could assist you further.

    >> Follow-up: When I tried to print the report to a PDF printer, I get no error, just an empty file.

    Please check that you are calling the report.Run() before exporting the report. Also, check the report.Document.Pages is being populated with multiple pages.

    Attachment: PictureControlSample.zip

  • Posted 27 October 2023, 11:16 am EST

    Thanks for the reply.

    I tested your sample and it works. However, I did some more testing and it appears that the overflow occurs when I use a TIFF file as the image. I have attached a TIFF file I used for testing.

    This works with AR12 but fails in AR17.

  • Posted 29 October 2023, 4:52 pm EST

    Hi,

    The TIFF image format is not supported in Picture Control in ActiveReports 17. You may convert it to any supported format using any third-party tool like Aspose.Imaging and use it in the report.

    I converted the TIFF image shared by you to BMP format and then added it to Picture Control, but I could not observe any errors. I also tried exporting the report via PDF Export and TIFF Export, but things seem to be working fine at my end. Please refer to the attached sample and confirm the behavior using the same. If the issue still persists at your end, you may share your own stripped-down sample or edit the attached sample so that it reproduces the error and send it back to us for further investigation.

    Note: Picture control supports Base64 string, Byte, BMP, JPG, JPEG, JPE, GIF, PNG, EMF, and WMF formats in both GDI and CrossPlatform compatibility modes.

    You may refer to the following links for more information:

    Attachment: PictureControlSample.zip

  • Posted 30 October 2023, 5:18 am EST

    To say that is disappointing is an understatement. So a capability in AR 12 is no longer available in AR17? This presents a problem for us since we have thousands of TIFF images that are placed on reports that are generated by a system that only produces TIFF files.

    What was this capability removed in AR17?

    Is there any way to convert the format on-the fly in memory without having to output it to a file? To have to write a file for every data record at run-time would be terrible. Having to resort to an additional $1,000 third-party API to do this is also not acceptable.

    Any other suggestions would be appreciated.

  • Posted 30 October 2023, 5:43 pm EST

    Hi,

    We apologize for the inconvenience caused to you. We have escalated this issue to our development team and will get back to you as soon as we receive any updates from them [AR-31986].

  • Posted 30 October 2023, 11:01 pm EST

    Hi,

    The developers are looking into the issue. In the meantime, as a workaround without using a third-party API, you can store your TIFF images as PNG images in a memory stream and load the same into your report.

    Please refer to the following code to do so:

    public Image GetImage()
    {
        string imagePath = "TIFFImage.tiff";
        Image image;
        using (FileStream fileStream = new FileStream(imagePath, FileMode.Open))
        {
            MemoryStream stream = new MemoryStream();
            fileStream.CopyTo(stream);
            image = Image.FromStream(stream);
            image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            image = Image.FromStream(stream);
        }
        return image;
    }
    

    You may also refer to the attached sample demonstrating adding a TIFF image to the Section Report without using any third-party API.

    Hope this helps!

    Attachment: PictureControlSample_Updated.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels