Delphi - get bitmap from TImageList

I am adding an image to an image, for example here - Add a png image to an imagelist at runtime using Delphi XE . The problem occurs when getting a bitmap from this list and saving it to the hard drive.

bmp:=tbitmap.create; imagelist.getbitmap(0,bmp); bmp.savetofile() 

this happens in many white BMP files, and a few with the image. it should be very easy, but I can’t understand what is wrong.

LE: The example was more like pseudo-code. code below:

list filling

  FImageList := TImageList.Create(nil); FImageList.Masked:=false; FImageList.ColorDepth:=cd32bit; FImageList.SetSize(32,32);//I am sure that all images are 32x32 while not dsTemp.eof do//dstemp is a Tdatasetdescendant begin ststream := dsTemp.CreateBlobStream(dsTemp.FieldByName('FLAG'), bmRead); pngImage := TPngImage.Create; pngImage.LoadFromStream(ststream); btBitmap := TBitmap.Create; btBitmap.PixelFormat := pf32bit; btBitmap.Width := pngImage.Width ; btBitmap.Height := pngImage.Height ; pngImage.AssignTo(btBitmap); btBitmap.AlphaFormat:=afIgnored; res := FImageList.Add(btBitmap,nil); // pngImage.savetofile('C:\a\'+inttostr(res)+'.png');-works. image is ok // btBitmap.savetofile('C:\a\'+inttostr(res)+'.bmp');-works. image is ok dsTemp.Next; freeandnil(btBitmap); freeandnil(pngImage); end; 

problem loading raster image

  for iPos := 0 to FImageList.Count-1 do begin btBitmap := tbitmap.create; FImageList.GetBitmap(iPos,btBitmap); btBitmap.savetofile('C:\a\'+inttostr(iPos)+'thr.bmp');//creates the bitmap, but it is white end; 

Edit after the question has been closed: more downvotes, please! Thanks

+4
source share
2 answers

This will definitely help if you can give an example for images that do not work. In the meantime, you can try playing around with this code:

 bmp.PixelFormat := pf32bit; bmp.AlphaFormat := afDefined; ImageList.GetBitmap(0, bmp); 
+5
source

Based on Uwe Raabe's answer , I make it work. Decision:

  for iPos := 0 to FImageList.Count-1 do begin btBitmap := tbitmap.create; btBitmap.PixelFormat := pf32bit; btBitmap.AlphaFormat := afIgnored; FImageList.GetBitmap(iPos,btBitmap); btBitmap.savetofile('C:\a\'+inttostr(iPos)+'thr.bmp'); end; 

Bitmaps are now saved correctly.

+6
source

Source: https://habr.com/ru/post/1445636/


All Articles