ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Saving monochrome bitmap as PNG ignores the 2 palette colors and uses always b/w
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Harald Lampke

Germany
4 Posts

Posted - Aug 25 2026 :  04:19:09  Show Profile  Reply
Assume a monochrome (1 bit per pixel) IEImage with two palette entries that are not black and white.
Saving such an image in PNG format generates a PNG file with black and white color, not respecting the two palette colors.


// Create IEBitmap
Bmp := TIEBitmap.Create;

// Load monochrome bitmap with green and blue color and keep palette (don't convert to 24 bit)
Bmp.ParamsEnabled := true;
if Bmp.Params.Read('Bear_green_blue.bmp') then begin
   if (Bmp.Params.BitsPerSample * Bmp.Params.SamplesPerPixel <= 8) then begin
      Bmp.Params.NativePixelFormat := true;
   end;
end;
if Bmp.Read('Bear_green_blue.bmp') then ...

// Save bitmap as PNG
Bmp.ParamsEnabled := true;
Bmp.Params.NativePixelFormat := true;
if Bmp.Write('Bear_green_blue.bmp', ioPNG) then ... // the saved file uses black and white instead of green and blue

// Free IEBitmap
Bmp.Free;


xequte

39520 Posts

Posted - Aug 25 2026 :  21:30:29  Show Profile  Reply
Hi Harald

The issue is not the loading, but the saving.

This creates a black and white image:
ImageEnView1.IO.Params.NativePixelFormat := TRUE;
ImageEnView1.IO.LoadFromFile('D:\Bear_green_blue.bmp');


This maintains the input colors:
ImageEnView1.IO.Params.NativePixelFormat := FALSE;
ImageEnView1.IO.LoadFromFile('D:\Bear_green_blue.bmp');


The reason is that if you enable NativePixelFormat, it treats a 1bit BMP as ie1g, which means its two colors are treated as black and white. You are better to count the colors after loading, choose an appropriate PixelFormat and then save to PNG.

Ensure AutoSetBitDepth is enabled:

http://www.imageen.com/help/TIEGlobalSettings.AutoSetBitDepth.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: