How to convert TBitMap 32bit to 24bit? [solved] lazarus / 39-Graphics ---------------------------------------------------------------------- Demi · 2013-02-20 11:17 Hello everybody! Code: [Select] bmap:=TBitMap.Create;  bmap.Assign(Bitmap);  //  Bitmap is 32bit.  bmap.PixelFormat:=pf24bit;  // Result - black rectangle How to convert TBitMap 32bit to 24bit? ---------------------------------------------------------------------- circular · 2013-02-20 12:10 Do you mean changing the encoding, or filling the alpha value with "opaque" ? ---------------------------------------------------------------------- Demi · 2013-02-20 12:34 I want to change the bit depth images. Image of 32-bit can not be printed on some printers. ---------------------------------------------------------------------- circular · 2013-02-20 12:40 Maybe with two LazIntfImage, one of 32-bit, one of 24-bit. Or by writing it to a stream and reading it again in a 24-bit bitmap. ---------------------------------------------------------------------- Demi · 2013-02-20 13:20 I can not find how to make a 24-bit LazIntfImage. (( Code: [Select]  test:=TLazIntfImage.Create(Bitmap.Width,Bitmap.Height);  test.LoadFromBitmap(Bitmap.Handle,Bitmap.MaskHandle);   bmap.LoadFromIntfImage(test);  bmap.PixelFormat:=pf24bit;  if bmap.PixelFormat = pf24bit then   Form1.Caption:='24';  if bmap.PixelFormat = pf32bit then   Form1.Caption:='32';      Result: Form1.Caption = 32 ---------------------------------------------------------------------- circular · 2013-02-20 13:38 I'm not sure you can assign PixelFormat like that. I've read somewhere that it is only provided for compatiblity with Delphi. In this example, I suppose you need to change the format of TLazIntfImage itself. So first set the DataDescription property of the LazIntfImage, then put the bitmap inside, and then load the bitmap from the LazIntfImage. Note that maybe LoadFromBitmap replaces the DataDescription, so you may need an additionnaly TLazIntfImage to load the bitmap, and to copy it you can for example use the Colors property. ---------------------------------------------------------------------- Demi · 2013-02-20 14:47 Code: [Select] test1:=TLazIntfImage.Create(Bitmap.Width,Bitmap.Height);  test:= Bitmap.CreateIntfImage;  ImgFormatDescription.Init_BPP24_B8G8R8_BIO_TTB(Bitmap.Width,Bitmap.He ight);  test1.DataDescription:=ImgFormatDescription;  test1.CopyPixels(test);       bmap:=TBitMap.Create;  bmap.PixelFormat:=pf24bit;  bmap.LoadFromIntfImage(test1);   if bmap.PixelFormat = pf24bit then   Form1.Caption:='24';   //   it's work!!!! Form1.Caption=24  if bmap.PixelFormat = pf32bit then   Form1.Caption:='32';               This code creates a 24-bit image. But all the transparent pixels become black. (( Result: https://dl.dropbox.com/u/19158664/screen.jpg ---------------------------------------------------------------------- circular · 2013-02-20 14:49 You need to copy pixels with a loop, and for each pixel, replace the alpha value with 65535 ---------------------------------------------------------------------- Demi · 2013-02-21 06:34 Thank you! It works! I make copy images (24-bit) for print. This images load to TImageList. Get image: Code: [Select] PrintList.GetBitmap(SelectLIm.tag,b); // b - 32-bit image ((( Print image:  Dest.StretchDraw(DestRect,b); // print black rectangle Code: [Select]Procedure Draw32Image(Dest:TCanvas;DestRect:TRect;Bitmap: TBitmap);  // Print 32-bit image to Printer.canvas. var   bmap:TBitMap;   test,test1:TLazIntfImage;   ImgFormatDescription: TRawImageDescription; begin  test1:=TLazIntfImage.Create(Bitmap.Width,Bitmap.Height);  test:= Bitmap.CreateIntfImage;  ImgFormatDescription.Init_BPP24_B8G8R8_BIO_TTB(Bitmap.Width,Bitmap.He ight);  test1.DataDescription:=ImgFormatDescription;  test1.CopyPixels(test);  bmap:=TBitMap.Create;  bmap.PixelFormat:=pf24bit;  bmap.LoadFromIntfImage(test1);  Dest.StretchDraw(DestRect,bmap);  bmap.free;  test.free;  test1.Free; end; ---------------------------------------------------------------------- circular · 2013-02-21 07:11 euh, that's the previous code ?