![]() |
Auf Canvas bei TImage zeichnen
Morgen.
Ich lade mir ein Bild in mein TImage:
Delphi-Quellcode:
Danach will ich einen gestrichelten Rahmen drumzeichnen.
image.picture.loadfromfile(filename);
Delphi-Quellcode:
Wie schaffe ich es, auch darauf zeichnen zu können, wenn ich KEIN Bitmap drin hab, sondern beispielsweise ein JPEG?
with image do
begin canvas.penstyle:=psdash; canvas.polygon([Point(0,0),Point(Width-1,0),Point(Width-1,Height-1),Point(0,Height-1)]); end; |
Re: Auf Canvas bei TImage zeichnen
Hi,
vlt. hilft dir das als Anregung...
Delphi-Quellcode:
uses
..., ShellAPI, ...; private { Private-Deklarationen } x1, y1, x2, y2 : Integer; public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Canvas.Pen.Mode := pmNotXOR; Canvas.Pen.Style := psDot; end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin If Shift = [ssLeft] Then Begin PatBlt(Canvas.Handle, 0, 0, ClientWidth, ClientHeight, Whiteness); Timer1.Enabled := False; Canvas.Brush.Style := bsClear; x1 := X; y1 := Y; x2 := X; y2 := Y; Canvas.Rectangle(x1, y1, x2, y2); End; end; procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin Panel1.Caption := IntToStr(x) + ':' + IntToStr(y); If Shift = [ssLeft] Then Begin Canvas.Rectangle(x1, y1, x2, y2); x2 := X; y2 := Y; Canvas.Rectangle(x1, y1, x2, y2); End; end; procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin Timer1.Enabled := True; end; procedure TForm1.Timer1Timer(Sender: TObject); begin Canvas.Pen.Style := psSolid; Canvas.Rectangle(x1, y1, x2, y2); Canvas.Pen.Style := psDot; end; ... end. |
Re: Auf Canvas bei TImage zeichnen
Da TImage.Picture.Graphic keinen Canvas hat könntest du die geladene Graphic (Jpg, Gif, Png, etc.)
in ein Bitmap wandeln und dann nach Lust und Laune darauf zeichnen. Nachteil ist das du dann beim speichen wieder in das Ausgangsformat umwandeln musst.
Delphi-Quellcode:
procedure TForm1.ConvertToBitmapImg(Image: TImage);
var TmpPic: TPicture; begin TmpPic := TPicture.Create; try TmpPic.Bitmap.Assign(Image.Picture.Graphic); Image.Picture.Bitmap.Assign(TmpPic.Bitmap); finally TmpPic.Free; end; end; procedure TForm1.FormCreate(Sender: TObject); begin ConvertToBitmapImg(Image1); end; |
Re: Auf Canvas bei TImage zeichnen
Danke. Abspeichern muss ich es gar nicht.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:23 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