I have a Flexcel report that needs to include images that are loaded from a bmp file. If there isn't a bitmap, it shows an image loaded from a PNG file instead. This works fine on my dev machine but on the deployment systems it is running on Windows server in IIS. And while a report with just the PNGs is fine, accessing the bitmaps causes a GDI+ failure. Is there an operation I can do on the loaded bitmap that will stop FlexCel needing to do whatever it is doing with GDI+?
System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(Stream stream, ImageFormat format)
at Abeta.ManagementReports.Flex.ReportPrimary.get_DetailImage()
at lambda_method(Closure , ReportPrimary )
at FlexCel.Report.TLinqFieldDefinitions`1.GetValue(T obj, Int32 column)
at FlexCel.Report.TLinqDataTableState`1.GetValue(Int32 column)
at FlexCel.Report.PosDouble.Decode(Int32 RequestCountry)
(not sure if the stack is good, as it includes CreateWikiPage further down...)
Further info: The BMP files are fine in Windows Explorer and Paint. Hmm, just checked, and they are black and white images only, not colour. Could there be palette issues?
I think ignore me for a while, unless you have some magic insight. I've added code to try to transform the Bitmap, and the eror is now that the get_Width has an invalid parameter. I shall have to verify my bitmap is good somehow (I've already done as much as I can but obviously something not right)
Hi,
I am not sure on what can be happening, but bmps are always problematic since they are a windows format. There are indeed some types of bmp that GDI+ might not like. If possible, try using pngs always. In fact, FlexCel by default converts those bmps to pngs internally (using GDI+) and stores them in the xls/x file as pngs. Because while it is possible to store bmps directly in an xls/x file, they are stored uncompressed, and unless they are very small, they will end up in huge files.
I sadly don't have much more insight than that, if you have an specific file that is giving issues I can take a look, but it is likely just that GDI+ doesn't know how to handle it. We don't do anything special here, just call GDI+ to convert the bmp to png.
Ps: about the stack trace, what happens is just that it is obfuscated, that's why the strange names. I can get the real stack trace from that one here, so it is no problem. But it doesn't tell us much, only that GDI+ failed to load that particular bmp. As you said, it is probably a palette/ bit format issue.