Recent

Author Topic: Example from the beginning of IntfGraphics.pas works or not, regarding the targe  (Read 288 times)

jipété

  • Full Member
  • ***
  • Posts: 167
Hello,

if I start with a .xpm file (I have one), it works. (caution with CreateBitmap, unknown ! "s" needed : CreateBitmaps)

But if I want to change the texts ...XPM by ...BMP I get black images, pf24bit as pf32bit, PixelFormat present or not, adding SetSize or not.

Dunno what to do, dunno where to look...
The code :

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   BmpHnd,MaskHnd: HBitmap;
  4.   Bitmap1: TBitmap;
  5.   IntfImg1: TLazIntfImage;
  6.   ReaderXPM: TLazReaderXPM;
  7.   WriterXPM: TLazWriterXPM;
  8.   ReaderBMP: TLazReaderBMP;
  9.   WriterBMP: TLazWriterBMP;
  10. {begin // that part works fine
  11.   Bitmap1:=TBitmap.Create;  // create a bitmap (or use an existing one)
  12.   IntfImg1:=TLazIntfImage.Create(0,0,[riqfRGB, riqfAlpha, riqfMask]);  // create the raw image for the screenformat you want
  13.   ReaderXPM:=TLazReaderXPM.Create;  // create the XPM reader
  14.   IntfImg1.LoadFromFile('filenamein.xpm',ReaderXPM);  // load the image
  15.   IntfImg1.CreateBitmaps(BmpHnd,MaskHnd);  // create the bitmap handles
  16.   Bitmap1.Handle:=BmpHnd;  // apply handles to the Bitmap1
  17.   Bitmap1.MaskHandle:=MaskHnd;
  18.   ReaderXPM.Free;  // clean up
  19.   IntfImg1.Free;
  20.   // do something with the Bitmap1
  21.   // nothing to do...
  22.   IntfImg1:=TLazIntfImage.Create(0,0,[]);   // create the raw image
  23.   IntfImg1.LoadFromBitmap(Bitmap1.Handle,Bitmap1.MaskHandle);  // load the raw image from the bitmap handles
  24.   WriterXPM:=TLazWriterXPM.Create;  // create the XPM writer
  25.   IntfImg1.SaveToFile('filenameout.xpm',WriterXPM);  // save image to file
  26.   WriterXPM.Free;  // clean up
  27.   IntfImg1.Free; }
  28. //
  29. begin   // BMP   black image size ok
  30.   Bitmap1:=TBitmap.Create;  // create a bitmap (or use an existing one)
  31.   Bitmap1.PixelFormat:=pf24bit; // added by me
  32.   Bitmap1.SetSize(TargetImg.Width, TargetImg.Height);
  33. //ok  showMessage(inttostr(TargetImg.Width)+' '+inttostr(TargetImg.Height));
  34.   IntfImg1:=TLazIntfImage.Create(0,0,[riqfRGB, riqfAlpha, riqfMask]);  // create the raw image for the screenformat you want
  35.   ReaderBMP:=TLazReaderBMP.Create;  // create the BMP reader
  36.   IntfImg1.LoadFromFile('filenamein24.bmp',ReaderBMP);  // load the image
  37.   IntfImg1.CreateBitmaps(BmpHnd,MaskHnd);  // create the bitmap handles
  38.   Bitmap1.Handle:=BmpHnd;  // apply handles to the Bitmap1
  39.   Bitmap1.MaskHandle:=MaskHnd;
  40.   ReaderBMP.Free;  // clean up
  41.   IntfImg1.Free;
  42.   // do something with the Bitmap1
  43.   // nothing to do...
  44.   IntfImg1:=TLazIntfImage.Create(0,0,[]);   // create the raw image
  45.   IntfImg1.LoadFromBitmap(Bitmap1.Handle,Bitmap1.MaskHandle);  // load the raw image from the bitmap handles
  46.   WriterBMP:=TLazWriterBMP.Create;  // create the XPM writer
  47.   IntfImg1.SaveToFile('filenameout24.bmp',WriterBMP);  // save image to file
  48.   WriterBMP.Free;  // clean up
  49.   IntfImg1.Free;
  50. //
  51. //begin   // BMP   black image size ok
  52.   Bitmap1:=TBitmap.Create;  // create a bitmap (or use an existing one)
  53.   Bitmap1.PixelFormat:=pf32bit; // added by me
  54.   Bitmap1.SetSize(TargetImg.Width, TargetImg.Height);
  55.   IntfImg1:=TLazIntfImage.Create(0,0,[riqfRGB, riqfAlpha, riqfMask]);  // create the raw image for the screenformat you want
  56.   ReaderBMP:=TLazReaderBMP.Create;  // create the BMP reader
  57.   IntfImg1.LoadFromFile('filenamein32.bmp',ReaderBMP);  // load the image
  58.   IntfImg1.CreateBitmaps(BmpHnd,MaskHnd);  // create the bitmap handles
  59.   Bitmap1.Handle:=BmpHnd;  // apply handles to the Bitmap1
  60.   Bitmap1.MaskHandle:=MaskHnd;
  61.   ReaderBMP.Free;  // clean up
  62.   IntfImg1.Free;
  63.   // do something with the Bitmap1
  64.   // nothing to do...
  65.   IntfImg1:=TLazIntfImage.Create(0,0,[]);   // create the raw image
  66.   IntfImg1.LoadFromBitmap(Bitmap1.Handle,Bitmap1.MaskHandle);  // load the raw image from the bitmap handles
  67.   WriterBMP:=TLazWriterBMP.Create;  // create the XPM writer
  68.   IntfImg1.SaveToFile('filenameout32.bmp',WriterBMP);  // save image to file
  69.   WriterBMP.Free;  // clean up
  70.   IntfImg1.Free;
  71. end;

Thanks,
In the zip are two bmp files, one 24bits and the other 32 :
« Last Edit: June 19, 2024, 12:49:38 pm by jipété »

 

TinyPortal © 2005-2018