procedure SchattenBitmap(b: TBitmap; Schatten, Transparenz: TColor; xversatz,
yversatz: shortint);
var
x, y: integer;
p: PBytearray;
hlp, merk: TBitmap;
rs, gs, bs, rt, gt, bt: Byte;
begin
hlp := TBitmap.create;
merk := TBitmap.create;
b.pixelformat := pf24bit;
hlp.pixelformat := pf24bit;
merk.pixelformat := pf24bit;
hlp.width := b.width;
hlp.height := b.height;
merk.width := b.width;
merk.height := b.height;
hlp.canvas.draw(0, 0, b);
merk.canvas.draw(0, 0, b);
schatten := colortorgb(schatten);
transparenz := colortorgb(transparenz);
rs := getrvalue(schatten);
gs := getgvalue(schatten);
bs := getbvalue(schatten);
rt := getrvalue(transparenz);
gt := getgvalue(transparenz);
bt := getbvalue(transparenz);
for y := 0 to hlp.height - 1 do begin
p := hlp.scanline[y];
x := 0;
while x <= hlp.width * 3 - 1 do begin
if (p[x] <> bt) or (p[x + 1] <> gt) or (p[x + 2] <> rt) then begin
p[x] := bs;
p[x + 1] := gs;
p[x + 2] := rs;
end;
inc(x, 3);
end;
end;
b.height := b.height + yversatz;
b.width := b.width + xversatz;
b.canvas.brush.color := transparenz;
b.canvas.FillRect(b.canvas.cliprect);
b.canvas.draw(xversatz, yversatz, hlp);
merk.transparentcolor := transparenz;
merk.transparent := true;
b.canvas.draw(0, 0, merk);
b.transparentcolor := b.canvas.brush.color;
b.transparent := true;
merk.free;
hlp.free;
end;
// --- Beispielaufrufe ---
procedure TForm1.Button6Click(Sender: TObject);
var
bmp: TBitmap;
begin
bmp := TBitmap.create;
bmp.loadfromfile('d:\bilder\aaa256.bmp');
SchattenBitmap(bmp, $998899, bmp.transparentcolor, 15, 15);
canvas.draw(0, 0, bmp);
bmp.free;
end;
procedure TForm1.Button7Click(Sender: TObject);
var
bmp: TBitmap;
transcolor: TColor;
begin
bmp := TBitmap.create;
bmp.loadfromfile('d:\bilder\vogel.bmp');
transcolor := bmp.canvas.pixels[0, bmp.height - 1]; // linke untere Ecke
SchattenBitmap(bmp, clgray, transcolor, 7, 10);
image1.canvas.draw(10, 10, bmp);
bmp.free;
end;