Question
What's the best way to draw a bitmap with a per-pixel alpha onto a control's Canvas?
My bitmap data is stored in a 2d array of 32-bit pixel values.
T32BitPixel = packed record
Blue : byte;
Green : byte;
Red : byte;
Alpha : byte;
end;
My control is a descendent of TCustomTransparentControl.
Background
For a GUI I'm building I need to draw semi-transparent controls over other controls and textured backgrounds. The control graphics are created using AggPasMod (a port of Anti-Grain Geometry).
TCustomTransparentControl.Canvas.Handle provides access to the device context for drawing but I'm not sure how to blit the pixel data from there.
AlphaFormat
toafPremultiplied
to let VCL properly calculate R,G,B from the alpha channel if you've got a recent Delphi version. If not, seeAC_SRC_ALPHA
inBLENDFUNCTION
s documentation for how it is done. – Sertac AkyuzafPremultiplied
after you've setup pixel data. Move theBitmap.AlphaFormat := afPreMultiplied;
line just beforeBlendFunction.BlendOp :=..
line. – Sertac Akyuz