Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Einen Ausschnitt einer Metafile in eine Metafile kopieren. (https://www.delphipraxis.net/181622-einen-ausschnitt-einer-metafile-eine-metafile-kopieren.html)

Bjoerk 29. Aug 2014 16:08

Einen Ausschnitt einer Metafile in eine Metafile kopieren.
 
Einen Ausschnitt einer Metafile in eine Metafile kopieren.

Ich dachte eigentlich daß man das so eventuell machen könnte, geht aber nicht. Er kopiert so immer die ganze Metafile? :gruebel:

Delphi-Quellcode:
procedure TDrawPad.CopySelectedRectToClipboard(const SelectRect: TFloatRectEx);
var
  ppMM: double;
  Rect: TRect;
  MF: TMetaFile;
  MC: TMetaFileCanvas;
begin
  if SelectRect.Angle = 0 then
  begin
    ppMM := PlotDevice[csDefault].ppMM;
    Rect.Left := Round(ppMM * SelectRect.P1.X);
    Rect.Top := Round(ppMM * SelectRect.P1.Y);
    Rect.Right := Round(ppMM * SelectRect.P2.X);
    Rect.Bottom := Round(ppMM * SelectRect.P2.Y);
    MF := TMetaFile.Create;
    try
      MF.Width := Round(ppMM * SelectRect.Width);
      MF.Height := Round(ppMM * SelectRect.Height);
      MC := TMetaFileCanvas.Create(MF, 0);
      try
        MC.Draw(-Rect.Left, -Rect.Top, FMetaFile);
      finally
        MC.Free;
      end;
      Clipboard.Assign(MF);
      MF.SaveToFile('Test.emf');
    finally
      MF.Free;
    end;
  end;
end;

DeddyH 29. Aug 2014 16:59

AW: Einen Ausschnitt einer Metafile in eine Metafile kopieren.
 
Meintest Du evtl. MC.CopyRect statt MC.Draw?

[edit] Nach kurzer Recherche würde das so auch nicht funktionieren, vielleicht hilft Dir das hier weiter: http://www.borlandtalk.com/metafile-...t-vt38344.html [/edit]

Bjoerk 29. Aug 2014 19:47

AW: Einen Ausschnitt einer Metafile in eine Metafile kopieren.
 
CopyRect und Bitblt sind ja Pixelzeugs.

EnumEnhMetaFile ist nur was für "Männer ohne Nerven" und PlayEnhMetaFile braucht ein hdc.

So stimmt schonmal die Bildgröße, aber Bild ist leer bzw. verschoben:
Delphi-Quellcode:
  IntersectClipRect(MC.Handle, Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
  MC.Draw(0, 0, FMetaFile);
Dito:
Delphi-Quellcode:
  IntersectClipRect(MC.Handle, Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
  MC.Draw(-Rect.Left, -Rect.Top, FMetaFile);
???

DeddyH 29. Aug 2014 20:32

AW: Einen Ausschnitt einer Metafile in eine Metafile kopieren.
 
Der hDC für PlayEnhMetaFile müsste doch TMetafileCanvas.Handle sein.

Bjoerk 29. Aug 2014 21:34

AW: Einen Ausschnitt einer Metafile in eine Metafile kopieren.
 
Delphi-Quellcode:
procedure DrawAntiAliased(Source: TMetafile; Dest: HDC; R: TRect);
begin
  Dec(R.Right);
  Dec(R.Bottom);
  PlayEnhMetaFile(Dest, Source.Handle, R);
end;
Weiß nicht, hdc ist zum Beispiel Bildschirm oder Printer.Handle. Kann ich denn als Dest das 2. Metafile.Handle oder MC.Canvas.Handle angben?

Edit: Jo. Geht. Thanx. Ist aber dasselbe wie Draw.

Bjoerk 30. Aug 2014 12:20

AW: Einen Ausschnitt einer Metafile in eine Metafile kopieren.
 
Liste der Anhänge anzeigen (Anzahl: 1)
Falls jemand probieren möchte - herzlich willkommen. :)

-> Anlage.

Krieg's nich hin.. :oops:

Bjoerk 30. Aug 2014 13:28

AW: Einen Ausschnitt einer Metafile in eine Metafile kopieren.
 
Hab's hetzt doch raus. "Er" will die Metafile immer von 0/0 bis Rect.BottomRight; :wall:
Delphi-Quellcode:
procedure TMetafileExampleForm.Draw;
var
  MC: TMetafileCanvas;
begin
  FMF2.Width := FRect.Right;
  FMF2.Height := FRect.Bottom;
  PaintBox2.Width := FMF2.Width;
  PaintBox2.Height := FMF2.Height;
  MC := TMetaFileCanvas.Create(FMF2, 0);
  try
    IntersectClipRect(MC.Handle, FRect.Left, FRect.Top, FRect.Right, FRect.Bottom);
    MC.Draw(0, 0, FMF1);
  finally
    MC.Free;
  end;
  Caption := Format('FMF2.Width %d FMF2.Height %d FRect.Width %d FRect.Height %d)',
    [FMF2.Width, FMF2.Height, FRect.Right - FRect.Left, FRect.Bottom - FRect.Top]);
  PaintBox2.Invalidate;
end;

Bjoerk 30. Aug 2014 14:22

AW: Einen Ausschnitt einer Metafile in eine Metafile kopieren.
 
Letzte Version.

Schönes WE. :)

Delphi-Quellcode:
procedure TMetafileExampleForm.Draw;
var
  MC: TMetafileCanvas;
  Temp: TMetaFile;
begin
  Temp := TMetaFile.Create;
  try
    Temp.Width := FRect.Right;
    Temp.Height := FRect.Bottom;
    MC := TMetaFileCanvas.Create(Temp, 0);
    try
      IntersectClipRect(MC.Handle, FRect.Left, FRect.Top, FRect.Right, FRect.Bottom);
      MC.Draw(0, 0, FMF1);
    finally
      MC.Free;
    end;
    FMF2.Width := FRect.Right - FRect.Left;
    FMF2.Height := FRect.Bottom - FRect.Top;
    PaintBox2.Width := FMF2.Width;
    PaintBox2.Height := FMF2.Height;
    MC := TMetaFileCanvas.Create(FMF2, 0);
    try
      MC.Draw(-FRect.Left, -FRect.Top, Temp);
    finally
      MC.Free;
    end;
  finally
    Temp.Free;
  end;
  Caption := Format('FMF2.Width %d FMF2.Height %d FRect.Width %d FRect.Height %d)',
    [FMF2.Width, FMF2.Height, FRect.Right - FRect.Left, FRect.Bottom - FRect.Top]);
  PaintBox2.Invalidate;
end;


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