开发者

initializing a 48bpp bitmap from a file in c#

开发者 https://www.devze.com 2023-03-17 20:26 出处:网络
I write a 48bppRgb to a file but when I create a bitmap from this file it is 32bppArgb(object img2 has a 开发者_JS百科property PixelFormat.32bppArgb).

I write a 48bppRgb to a file but when I create a bitmap from this file it is 32bppArgb(object img2 has a 开发者_JS百科property PixelFormat.32bppArgb).

Minimized example:

Bitmap img1 = new Bitmap(100, 100, PixelFormat.Format48bppRgb);
img1.Save("/img1.bmp");
Bitmap img2 = new Bitmap("/img1.bmp");

Why?


More than one problem. You didn't save the image in the BMP format. The default format for Image.Save(string) is PNG. The PNG encoder built into GDI+ doesn't support 48bpp images. Saving as a BMP requires specifying the image format:

        Bitmap img1 = new Bitmap(100, 100, PixelFormat.Format48bppRgb);
        img1.Save("c:/temp/img1.bmp", ImageFormat.Bmp);

You'll however find that the BMP encoder doesn't support 48bpp images either, you'll get a 24bpp image when you load it back. None of the codecs supports 48bpp.

There's lots of missing functionality in GDI+. ImageFormat.Icon doesn't work for example, it actually saves a PNG. And support for any of the Indexed pixels formats is quite poor. If you need this kind of support then you'll need a professional imaging library. LeadTools or ImageMagick are the usual choices.

0

精彩评论

暂无评论...
验证码 换一张
取 消