Autor Beitrag
g1o2k4
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 493



BeitragVerfasst: Sa 12.09.09 21:37 
hallo.

ich habe ein globales metafile für ein bild. bei jeder mausbewegung werden in dem metafile die linien gespeichert und am ende des mousemove events wird der neue strich in ein image gezeichnet.

ich möchte aber bei jeder mausbewegung den strich an das alte metafile anfügen und am ende der mausbewegung das gesamte bild aus dem metafile neu zeichnen. wie füge ich also neue striche an ein bestehendes metafile, in dem schon informationen stehen an?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if mousedown = true then
begin

with TMetafileCanvas.Create(wmf, 0) do
  begin
  Brush.Color:= clblack;

  //neue linie
  moveto(p.X, p.y);
  Lineto(x,y);
  p.X := x;
  p.Y := y;

  free;
  end;

  //daten aus wmf auf image1 malen.
  image1.Canvas.Draw(0,0, wmf);
end;
end;


also in wmf soll der gesamte metafile inhalt des bildes sein. in canvas bleibt es ja erhalten bis man es übermalt aber halt nicht in dem wmf.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 13.09.09 09:29 
Was funktioniert denn mit dem Quelltext nicht? Abgesehen davon, dass der Ressourcenschutzblock (try..finally) fehlt, funktioniert das so normal bei mir. :nixweiss:

Der einzige echte Fehler, den ich auf Anhieb sehe, ist:
ausblenden Delphi-Quelltext
1:
if mousedown = true then					
Hier habe ich mal ein kleines Beispiel gebastelt, wann es schief geht:
www.delphi-forum.de/....php?p=548760#548760
Mehr dazu steht hier:
www.delphi-treff.de/...olean-werten/page/4/
Und warum das auch vollkommen unlogisch ist:
www.delphi-forum.de/....php?p=560637#560637
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 15.09.09 12:43 
Du erzeugst ständig ein neues Metafile. Erzeuge dir deine Metafile einmalig und nutze dieses dann den gesamten Verlauf über ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 15.09.09 19:57 
Solange wmf nicht wieder immer neu erstellt wird, ist das schon richtig so (wenn auch das Erstellen des Canvas jeweils auch nicht notwendig wäre).

Ich habe es genauso auch ausprobiert, bei mir funktioniert das so absolut problemlos. :nixweiss:
Der Fehler liegt also in dem Teil des Quelltext, der nicht gepostet wurde. Und den habe ich im Test natürlich automatisch so ergänzt, dass er korrekt funktioniert...
g1o2k4 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 493



BeitragVerfasst: Di 15.09.09 20:52 
ich weiß das ständig ein neus metafile erstellt wird.

aber ich habs auch so probiert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
oncreate:
  wmf := TMetafile.Create; //global
  mfc := TMetafileCanvas.Create(wmf, 0); //global
  mfc.Brush.Color := clblack;
  wmf.Height := Image1.Height;
  wmf.Width := Image1.Width;


onmousemove:
  if mousedown = true then
  begin

      mfc.moveto(p.X, p.Y);
      mfc.Lineto(X, Y);
      p.X := X;
      p.Y := Y;

      Image1.Canvas.Draw(0, 0, wmf);
  end;


so wie ich das mit den metafiles verstanden hab müssten dann in wmf alle metainfos gespeichert sein bzw bei mouse move immer ein neues lineto, moveto geaddet werden...