Reputation: 145
Delphi.
I have an ImageList (either TImageList, or DevExpress's TcxImageList) that contains PNG pictures using alpha channel. The RGB part of the picture is a black square. The alpha channel contains the shape of the real picture. I want to change the colour of the black square, while keep the shape in the alpha channel. (So eventually i change the colour of the picture-shape-icon-whatever.)
I tried many ways, without success. I tried to change the properties of the lists, and export RGB and alpha separeted.
TImageList: the mask is not exported. If i do SaveToFile, it saves a 0 byte file, and Replace also says the mask's size is incorrect (0*0 px)
BMPimg := TBitmap.Create;
BMPmask := TBitmap.Create;
Try
TImageListHack(il1).GetImages(0, BMPimg, BMPmask);
BMPimg.Canvas.Brush.Color := clRed;
BMPimg.Canvas.FillRect(TRect.Create(0, 0, BMPimg.Width, BMPimg.Height));
il1.Replace(i, BMPimg, BMPmask);
End;
Finally
BMPimg.Free;
BMPmask.Free;
End;
TcxImageList: it loads picture+mask into BMPimg, and the mask is a black square instead of the shape in the BMPmask.
BMPimg := TBitmap.Create;
BMPmask := TBitmap.Create;
Try
il1.GetBitmap(i, BMPimg);
il1.GetMask(i, BMPmask);
BMPimg.Canvas.Brush.Color := clRed;
BMPimg.Canvas.FillRect(TRect.Create(0, 0, BMPimg.Width, BMPimg.Height));
il1.Replace(i, BMPimg, BMPmask);
Finally
BMPimg.Free;
BMPmask.Free;
End;
How can i change the foreground color while the keep the alpha channel in imagelist's PNG images?
Upvotes: 3
Views: 693
Reputation: 145
Ehhhh.
I have to set manually the sizes of the BMPmask, then the mask comes right.
...
BMPmask.Width := il1.Width;
BMPmask.Height := il1.Height;
TImageListHack(il1).GetImages(0, BMPimg, BMPmask);
...
Upvotes: 3