Imagesharp: bmp written is not supported by Chrome or Firefox

Created on 16 Apr 2019  路  9Comments  路  Source: SixLabors/ImageSharp

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have verified that I am running the latest version of ImageSharp
  • [x] I have verified if the problem exist in both DEBUG and RELEASE mode
  • [x] I have searched open and closed issues to ensure it has not already been reported

Description

When saving image as bmp it can not be seen with Chrome or Firefox, however it can be read by MS Paint.

This started to happen with 1.0.0-beta0006 when i compare the produced image with one from 1.0.0-beta0005 i can see that the bmp header is different....

images.zip

Steps to Reproduce

c# using (var image = Image.Load<Rgb24>(mem)) { // issue here image.SaveAsBmp(fullMem); }

System Configuration

Seen under Windows and Linux

  • ImageSharp version: 1.0.0-beta0006
  • Other ImageSharp packages and versions:
  • Environment (Operating system, version and so on):
  • .NET Framework version:
  • Additional information:
bug bmp

Most helpful comment

we have indeed changed the bitmap header in beta0006 to V4 to support bitmaps with transparency. As @JimBobSquarePants said, chrome and firefox should support those.

I checked the imagesharp bitmap encoder and at first glance i can not spot an error.
I was thinking maybe we should write V3 bitmap header as default and keep writing V4 headers as optional. I will look further into this the next days.

All 9 comments

header_compare

Odd. V4 bitmaps should be supported. @brianpopow do you have any insight here?

http://entropymine.com/jason/bmpsuite/bmpsuite/html/bmpsuite.html

we have indeed changed the bitmap header in beta0006 to V4 to support bitmaps with transparency. As @JimBobSquarePants said, chrome and firefox should support those.

I checked the imagesharp bitmap encoder and at first glance i can not spot an error.
I was thinking maybe we should write V3 bitmap header as default and keep writing V4 headers as optional. I will look further into this the next days.

Thanks @brianpopow appreciate it! That sounds like a sensible plan.

update: gimp can also not read the image produced with beta006, it complains with:
"Unrecognized or invalid BMP compression format."

beta0006_03_to_01.zip

the problem is the incorrect 0x03, when i change it to 0x00 it works and i can load it into gimp and Chrome.

header_compare_2

issue comes most probably from BmpEncoderCore.cs / Line 131: "Compression = BmpCompression.BitFields".

Why is BitFields here used, aren't the pixels anyway stored in memory byte by byte, thus "Compression = BmpCompression.RGB" should do the trick.

The v4 header does not seem to be the issue here. It seems to be combination of V4 header + 24 bits per pixel + Bitfields compression which chrome and firefox does not like. Bitfields with 32 bits per pixel does work with chrome, firefox and irfanview.

@pammann-work: as i said in my first post. The intention for using V4 header (with Bitfields) was to support transparency, but in your case with 24 bpp, there is no transparency anyway. Your hack for changing from bitfields (0x03) to no compression (0x00) works, because we use 8 bit per color channel with bitfields. This is essentially the same as uncompressed (without transparency).
I wanted to change the bitmap header to default to V3, which implies no compression. V3 headers should be supported by almost all decoders.

Fixed with #889

Was this page helpful?
0 / 5 - 0 ratings