Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#2

AW: Komponente mit GDI+ und Transparenten Hintergrund

  Alt 16. Jan 2013, 10:25
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.
Miniaturansicht angehängter Grafiken
gp.jpg  
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat