PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

Adding BMP gives "Image format not supported." exc
http://forum.pdfsharp.de/viewtopic.php?f=3&t=694
Page 1 of 1

Author:  blackjack2150 [ Fri Apr 03, 2009 8:50 am ]
Post subject:  Adding BMP gives "Image format not supported." exc

Hi.

I wrote a small free application that converts image files to PDF documents. When using it on a BMP file, one user encountered this error:

Code:
NotImplementedException: Image format not supported.
at PdfSharp.Pdf.Advanced.PdfImage.InitializeNonJpeg()
at PdfSharp.Pdf.Advanced.PdfImage..ctor(PdfDocument document, XImage image)
at PdfSharp.Pdf.Advanced.PdfImageTable.GetImage(XImage image)
at PdfSharp.Pdf.PdfPage.GetImageName(XImage image)
at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.GetImageName(XImage image)
at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.Realize(XImage image)
at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.DrawImage(XImage image, Double x, Double y, Double width, Double height)
at PdfSharp.Drawing.XGraphics.DrawImage(XImage image, Double x, Double y)
at PdfSharp.Drawing.XGraphics.DrawImage(XImage image, Int32 x, Int32 y)


I was skeptic at first, but he sent me the file and it is correct and accurate. It's a BMP file, which can even be displayed by the basic viewer of TotalCommander, pressing F3.

Debugging the application I found the LOC where the exception is thrown.
It's the one where "DrawImage" is called:

Code:
PdfDocument doc = new PdfDocument();
                doc.Pages.Add(new PdfPage());
                XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
                XImage img = XImage.FromFile(source);

                //adjust page size to fit image
                if (doc.Pages[0].Width < XUnit.FromPoint(img.Size.Width))
                    doc.Pages[0].Width = XUnit.FromPoint(img.Size.Width);

                if (doc.Pages[0].Height < XUnit.FromPoint(img.Size.Height))
                    doc.Pages[0].Height = XUnit.FromPoint(img.Size.Height);

                xgr.DrawImage(img, 0, 0, img.Size.Width, img.Size.Height);
               
                doc.Save(destinaton);
                doc.Close();


I tested with PDFSharp versions 1 and 1.20 beta and the result is the same. If needed I can provide the BMP file that causes this.

Thanks for your time and effort and keep up the good work!

Author:  Thomas Hoevel [ Tue Apr 07, 2009 8:06 am ]
Post subject: 

Hi!

We need the BMP to investigate this.

I sent you a PM.

Author:  Thomas Hoevel [ Tue Apr 07, 2009 9:06 am ]
Post subject: 

The image format is: Format16bppRgb555
(Specifies that the format is 16 bits per pixel; 5 bits each are used for the red, green, and blue components. The remaining bit is not used.)

I knew there was such a format but didn't know how to create it.

I'll let you know when it's implemented.

Author:  blackjack2150 [ Thu Apr 09, 2009 11:45 am ]
Post subject: 

Thanks for looking into it.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/