Hallo,
ich habe eine 100x100 Pixel Bitmap, welche außen weiß ist. Ich würde für diese Bitmap gerne weiß als transparente Farbe definieren und dann die Bitmap über eine andere (Hintergrund-) 100x100 Pixel Bitmap legen. Um das so enstehende Bild auf dem Formular zu visualisieren dachte ich an ein Image. Ich habe mir dazu folgenden Code überlegt:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;
type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private public end;
var Form1: TForm1; Image: TImage; Bmp1, Bmp2: TBitmap;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject); begin Bmp1 := TBitmap.Create; Bmp1.Height := 100; Bmp1.Width := 100; Bmp1.LoadFromFile('Bmp1.bmp');
Bmp2 := TBitmap.Create; Bmp2.Height := 100; Bmp2.Width := 100; Bmp2.TransparentMode := tmFixed; Bmp2.TransparentColor := clWhite; Bmp2.Transparent := true;
Image := TImage.Create(Form1); Image.Height := 100; Image.Width := 100;
Image.Picture.Bitmap := Bmp1; Image.Picture.Bitmap := Bmp2; Image.Parent := Form1; end;
end. |
Doch das unerwartete Endergebnis: Man sieht am Ende nur die zweite Bitmap. Es scheint so, dass bei
Image.Picture.Bitmap := Bmp2; der vorherige Bitmap-Inhalt einfach überschrieben wird.
Moderiert von
Narses: Code- durch Delphi-Tags ersetzt