Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Transparentes TImage zur Laufzeit (https://www.delphipraxis.net/149066-transparentes-timage-zur-laufzeit.html)

ghutzriop 13. Mär 2010 13:21


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;

daywalker9 13. Mär 2010 13:25

Re: Transparentes TImage zur Laufzeit
 
Versuch mal
Delphi-Quellcode:
image1.Canvas.Pen.Style := psSolid;
image1.Canvas.Brush.Style := bsSolid;

ghutzriop 13. Mär 2010 13:32

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.

Yheeky 13. Mär 2010 13:37

Re: Transparentes TImage zur Laufzeit
 
Hi,

schonmal

Delphi-Quellcode:
image2.Repaint;
am Ende probiert?

ghutzriop 13. Mär 2010 13:42

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.

DeddyH 13. Mär 2010 13:51

Re: Transparentes TImage zur Laufzeit
 
Delphi-Quellcode:
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;
Du solltest auf die Bitmap zeichnen statt auf das Image selbst. Und Höhe und Breite der Bitmap sollte man dann auch festlegen.

ghutzriop 13. Mär 2010 14:01

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