Hi Greg
How about something like this:
// Draws the specified bitmap onto another bitmap,
// if bTransparent is true then the bottom left pixel are used to determine the
// transparecny color
procedure DrawBitmapOntoImage(SourceBMP: TBitmap; // the bitmap to draw
DestCanvas: TCanvas; // the Canvas to draw onto
DestCanvasWidth: Integer; // The width of the canvas we are drawing on
DestCanvasHeight: Integer; // The Height of the canvas we are drawing on
iLeft: Integer;
iTop: Integer; // the position to draw SourceBMP
bTransparent: boolean); // if true then all pixels of the same color as the the bottom left pixel are drawn as transparen
var
TempBMP : TBitmap;
rctObject : Trect;
begin
tempbmp := TBitmap.create;
try
RctObject := rect(iLeft,
iTop,
iLeft + SourceBMP.width,
iTop + SourceBMP.Height);
// check that it doesn't extend beyond the end of the image
if RctObject.right > DestCanvasWidth then
RctObject.right := DestCanvasWidth;
if RctObject.bottom > DestCanvasHeight then
RctObject.bottom := DestCanvasHeight;
TempBMP.width := RctObject.right - RctObject.left;
TempBMP.height := RctObject.bottom - RctObject.top;
TempBMP.canvas.copymode := cmsrcCopy;
TempBMP.canvas.copyrect(rect(0, 0, TempBMP.width, TempBMP.height), DestCanvas, RctObject);
SourceBMP.width := RctObject.right - RctObject.left;
SourceBMP.height := RctObject.bottom - RctObject.top;
SourceBMP.transparent := bTransparent;
TempBMP.canvas.Draw(0, 0, SourceBMP);
if (bTransparent = false) then
DestCanvas.copyrect(RctObject, SourceBMP.canvas, rect(0, 0, SourceBMP.width, SourceBMP.height))
else
DestCanvas.copyrect(RctObject, TempBMP.canvas, rect(0, 0, TempBMP.width, TempBMP.height));
finally
tempbmp.free;
end;
end;
Nigel
Xequte Software
www.xequte.com
nigel@xequte.com