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
 dynamic bmp to png conversion problem
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

kowal

Poland
38 Posts

Posted - Jun 13 2022 :  14:55:52  Show Profile  Reply
I'm trying do save dynamically created bitmaps in png format with Transparency set on but with no good result.

Here is a snippet of my test code in which the problem may be probably seen.
I read the bitmap from the test file, and save it to be sure it is 32 bit with transparency set.
Then I read it into TIEBitmap object.

And here I get the PixelFormat of the IEBitmap object value ie24RGB not ie32RGB which I expect.

procedure TForm1.open_saveClick(Sender: TObject);
var bmp: TBitmap;
    iebmp: TIEBitmap;
    fn: string;
begin
  if odp.Execute() then
  begin
        fn := odp.FileName;

        bmp   := tBitmap.Create;
        bmp.TransparentMode := tmAuto;
        bmp.Transparent := true;
        bmp.LoadFromFile(fn);
        bmp.SaveToFile(fn);      // I save bmp with pf32bit

        iebmp := TIEBitmap.Create();
        iebmp.ParamsEnabled := True;
        iebmp.Params.BMP_HandleTransparency := True; // Alpha Channel will be saved (as a 32bit RGBA BMP)

        iebmp.Read(fn);       // iebmp.Pixelformat = ie24RGB

        iebmp.Write(StringReplace(fn,'.bmp','.png',[rfReplaceAll]));
        iebmp.Free;
        bmp.Free;
  end;
end;

May be the bitmap should be prepared in some different way, but don't know how to do it.


Kowalski



xequte

38610 Posts

Posted - Jun 13 2022 :  20:07:55  Show Profile  Reply
Hi Kowalski

If you are starting with a 24bit bitmap, there is no transparency, and even saving it as 32bit bitmap will only enable an alpha channel, but the image still won't contain any transparent pixels. Can you attach some example BMP files and show what you are a looking to do with them (e.g. how should transparent pixels be determined)?



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

kowal

Poland
38 Posts

Posted - Jun 14 2022 :  05:08:53  Show Profile  Reply
Hi,
this is the file I want to convert and the result of conversion
I intend to place png as a marker on the Google Maps.

The properties info from Windows is that it is 32 bit bmp image.

Go to Top of Page

xequte

38610 Posts

Posted - Jun 14 2022 :  15:04:52  Show Profile  Reply
Hi Kowalski

How about the following?

  // Convert a bitmap where the bottom-left pixel represents the transparent color to PNG
  bmp := TIEBitmap.Create;
  bmp.Read( 'D:\Glyph_Source.bmp');
  // Get transparent color (transColor is type TRGB)
  transColor := bmp.Pixels[ 0, bmp.Height - 1 ];
  bmp.SetTransparentColors( transColor, transColor, 0 );
  bmp.Write( 'D:\Glyph_Output.png');
  bmp.Free;






Nigel
Xequte Software
www.imageen.com
Go to Top of Page

kowal

Poland
38 Posts

Posted - Jun 15 2022 :  07:49:26  Show Profile  Reply
Hi Nigel
That works ok!
Thank you for your help!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: