![]() |
Transparentes TImage zur Laufzeit
Hallo, ich versuche ein TImage zur Laufzeit zu erzeugen. Auf das Bild soll etwas gezeichnet werden (in diesem Fall ein Punkt) und der Rest des Bildes transparent sein. Mein unten gezeigter Versuch führt jedoch zu einem komplett transparenten Bild, wobei auch der Punkt nicht mehr sichtbar ist.
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin image2:= TImage.Create(Form1); image2.Parent:=Form1; image2.Picture.Bitmap.TransparentColor := clwhite; image2.Transparent:=true; image2.Canvas.Brush.color:=clwhite; image2.Canvas.Pen.Color:=clwhite; image2.Canvas.Rectangle(0,0,image2.Width, image2.Height); image2.Canvas.Brush.color:=clgreen; image2.Canvas.Pen.Color:=clgreen; image2.Canvas.Ellipse(5,5,10,10); image2.Left:=50; image2.Top:=50; end; |
Re: Transparentes TImage zur Laufzeit
Versuch mal
Delphi-Quellcode:
image1.Canvas.Pen.Style := psSolid;
image1.Canvas.Brush.Style := bsSolid; |
Re: Transparentes TImage zur Laufzeit
Danke für die schnelle Antwort, es hilft mir aber leider nicht. Noch als Nebenbemerkung, wenn ich das TImage von Hand auf das Formular ziehe funktioniert alles wie es sollte.
|
Re: Transparentes TImage zur Laufzeit
Hi,
schonmal
Delphi-Quellcode:
am Ende probiert?
image2.Repaint;
|
Re: Transparentes TImage zur Laufzeit
Leider auch nicht.
Hier ist im Übrigen die gesamte exemplarische Unit1
Delphi-Quellcode:
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, jpeg, ExtCtrls; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; Image2: TImage; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin image2:= TImage.Create(Form1); image2.Parent:=Form1; image2.Picture.Bitmap.TransparentColor := clwhite; image2.Transparent:=true; image2.Canvas.Pen.Style := psSolid; image2.Canvas.Brush.Style := bsSolid; image2.Canvas.Brush.color:=clwhite; image2.Canvas.Pen.Color:=clwhite; image2.Canvas.Rectangle(0,0,image2.Width, image2.Height); image2.Canvas.Brush.color:=clgreen; image2.Canvas.Pen.Color:=clgreen; image2.Canvas.Ellipse(5,5,10,10); image2.Left:=50; image2.Top:=50; image2.Repaint; end; end. |
Re: Transparentes TImage zur Laufzeit
Delphi-Quellcode:
Du solltest auf die Bitmap zeichnen statt auf das Image selbst. Und Höhe und Breite der Bitmap sollte man dann auch festlegen.
procedure TForm1.FormCreate(Sender: TObject);
begin image2:= TImage.Create(self); image2.Parent:=self; image2.Picture.Bitmap.TransparentColor := clwhite; image2.Picture.Bitmap.Width := 15; image2.Picture.Bitmap.Height := 15; image2.Picture.Bitmap.Canvas.Pen.Style := psSolid; image2.Picture.Bitmap.Canvas.Brush.Style := bsSolid; image2.Picture.Bitmap.Canvas.Brush.color:=clwhite; image2.Picture.Bitmap.Canvas.Pen.Color:=clwhite; image2.Picture.Bitmap.Canvas.Rectangle(0,0,image2.Width, image2.Height); image2.Picture.Bitmap.Canvas.Brush.color:=clgreen; image2.Picture.Bitmap.Canvas.Pen.Color:=clgreen; image2.Picture.Bitmap.Canvas.Ellipse(5,5,10,10); image2.Left:=50; image2.Top:=50; image2.Transparent:=true; end; |
Re: Transparentes TImage zur Laufzeit
Vielen Dank, ich hab mir schon gedacht, dass ich einen fundamentalen Fehler gemacht habe.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:59 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz