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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 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

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Harald Lampke Posted - Aug 25 2026 : 04:19:09
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;


1   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Aug 25 2026 : 21:30:29
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