Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Komponente mit GDI+ und Transparenten Hintergrund (https://www.delphipraxis.net/172659-komponente-mit-gdi-und-transparenten-hintergrund.html)

SonnyBoyPro 16. Jan 2013 09:51

Komponente mit GDI+ und Transparenten Hintergrund
 
Hallo zusammen,
ich stehe vor einem Problem wo Ihr mir sicher weiterhelfen könnt. Ich habe bisher für eine Visualisierung eine Grafik mit Graphics32 gezeichnet. Aufgrund diverses Änderungen muss ich jetzt auf GDI+ umsteigen.
Das Zeichnen ist mal das geringere Problem, allerdings soll das ganze auf einen transparenten Hintergrund passieren (da hinter der Komponenten ein Bild als zusätzliche Anzeigevisualisierung dient).
Da sich die Darstellung aber mit der Zeit ändert (Maschinenvisualisierung) wird da auch immer wieder reingezeichnet und daher muss vor dem Zeichnen der Hintergrund wieder "clean" gemacht werden. Wie geht das? (Bei Graphic32 hab ich mit Layers gerarbeitet). Bei GDI+ hab ichs momentan noch nicht geschafft
Ansatz war mal:
Delphi-Quellcode:
Graphics := TGPGraphics.Create(Canvas.Handle);
Graphics.Clear(MakeColor(0, 0, 0, 0));
Aber damit wird der Hintergrund nur schwarz.....

Welche Komponenten oder Ansätze könnt Ihr mir empfehlen?

BG

Bummi 16. Jan 2013 10:25

AW: Komponente mit GDI+ und Transparenten Hintergrund
 
Liste der Anhänge anzeigen (Anzahl: 1)
kleines Beispiel, Paintbox liegt über dem Bild.

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,Gdipapi,Gdipobj, ExtCtrls, jpeg;

type
  TForm1 = class(TForm)
    Image1: TImage;
    PaintBox1: TPaintBox;
    procedure FormCreate(Sender: TObject);
    procedure PaintBox1Paint(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

Procedure AddSprechblase(graphics:TGPGraphics;Base:TGPPointF;SizeRect:TGPRectF;PenColor,BrushColor:TGPColor;Caption:String='';AngleWidth:Integer=20;TextHeight:Integer=10; FontName:String='Arial');
var
  Path : TGPGraphicsPath;
  Pen  : TGPPen;
  Brush : TGPSolidBrush;
  StringFormat:TGPStringFormat;
  FontFamily : TGPFontFamily;
  Font      : TGPFont;

begin
   Path:=TGPGraphicsPath.Create;
   Pen  := TGPPen.Create(PenColor);
   Brush := TGPSolidBrush.Create(BrushColor);
   StringFormat:= TGPStringFormat.Create;
   FontFamily := TGPFontFamily.Create(FontName);
   Font      := TGPFont.Create(FontFamily, TextHeight, FontStyleRegular, UnitPixel);
   if Base.Y > SizeRect.Y then Path.AddArc(SizeRect, 90 + AngleWidth, 360 - 2 * AngleWidth)
   else Path.AddArc(SizeRect, - 90 + AngleWidth, 360.0 - 2 * AngleWidth);
   Path.AddLine(Base,Base);
   path.CloseAllFigures;
   graphics.FillPath(brush, path);
   graphics.DrawPath(pen, path);
   if Length(Caption) > 0 then
      begin
        Brush.SetColor(PenColor);
        stringFormat.SetAlignment(StringAlignmentCenter);
        stringFormat.SetLineAlignment(StringAlignmentCenter);
        graphics.DrawString(Caption,-1,Font,Sizerect,stringformat,Brush)
      end;
   Path.Free;
   Pen.Free;
   Brush.Free;
   StringFormat.Free;
   FontFamily.Free;
   Font.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Paintbox1.BringToFront;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
var
 graphics:TGPGraphics;
begin
  graphics:=TGPGraphics.Create(Paintbox1.Canvas.Handle);
  graphics.SetSmoothingMode(SmoothingModeHighQuality);
  graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
  AddSprechblase(graphics,MakePoint(200.0,400.0),MakeRect(100.0,100.0,300,200),MakeColor(200,255,0,0),MakeColor(200,255,255,255),'Tescht',10,50);
  graphics.Free;
end;

end.

pustekuchen 16. Jan 2013 10:31

AW: Komponente mit GDI+ und Transparenten Hintergrund
 
Ich mach es so das ich mir eine Bitmap anlege auf die ich zeichne und dann mit TransparentBlt das ganze auf das Zielcanvas kopiere.

SonnyBoyPro 16. Jan 2013 11:16

AW: Komponente mit GDI+ und Transparenten Hintergrund
 
Danke Bummi für den Tip
Hast mir weitergeholfen!:thumb:


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:38 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz