View previous topic :: View next topic |
Author |
Message |
blackjack2150
Joined: 21 Aug 2008 Posts: 5
|
Posted: 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! |
|
Back to top |
|
 |
Thomas Hoevel

Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: Tue Apr 07, 2009 8:06 am Post subject: |
|
|
Hi!
We need the BMP to investigate this.
I sent you a PM. _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
 |
Thomas Hoevel

Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: 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. _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
 |
blackjack2150
Joined: 21 Aug 2008 Posts: 5
|
Posted: Thu Apr 09, 2009 11:45 am Post subject: |
|
|
Thanks for looking into it. |
|
Back to top |
|
 |
|