Given the Delphi TPicture, in which there is some descendant of TGraphic, I need to understand the pixel color and opacity. I think I should have different implementations for each class, and I think I have TPngImage. Is there transparency support in 32-bit bitmaps? Can I solve the problem in a more general way than the following:
procedure GetPixelColorAndTransparency(const Picture: TPicture; X, Y: Integer; out Color: TColor; out Opacity: Byte); var Bmp: TBitmap; begin if Picture.Graphic is TPngImage then begin Opacity := (TPngImage(Picture.Graphic).AlphaScanline[Y]^)[X]; Color := TPngImage(Picture.Graphic).Pixels[ X, Y ]; end else if Picture.Graphic is TBitmap then begin Color := Picture.Bitmap.Canvas.Pixels[ X, Y ]; Opacity := 255; end else begin Bmp := TBitmap.Create; try Bmp.Assign(Picture.Graphic); Color := Bmp.Canvas.Pixels[ X, Y ]; Opacity := 255; finally Bmp.Free; end; end; end;
source share