Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Auf Canvas bei TImage zeichnen (https://www.delphipraxis.net/70793-auf-canvas-bei-timage-zeichnen.html)

3_of_8 4. Jun 2006 23:49


Auf Canvas bei TImage zeichnen
 
Morgen.

Ich lade mir ein Bild in mein TImage:
Delphi-Quellcode:
image.picture.loadfromfile(filename);
Danach will ich einen gestrichelten Rahmen drumzeichnen.
Delphi-Quellcode:
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;
Wie schaffe ich es, auch darauf zeichnen zu können, wenn ich KEIN Bitmap drin hab, sondern beispielsweise ein JPEG?

Mackhack 5. Jun 2006 00:12

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.

turboPASCAL 5. Jun 2006 05:55

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;

3_of_8 5. Jun 2006 10:03

Re: Auf Canvas bei TImage zeichnen
 
Danke. Abspeichern muss ich es gar nicht.


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:54 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