Autor Beitrag
Tulkas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 21

WinXP SP2
Delphi7
BeitragVerfasst: Di 22.08.06 14:43 
Servus!

Mit welchem Befehl kann ich eine Linie auf dem Canvas eines Bitmaps löschen?


Moderiert von user profile iconChristian S.: Topic aus VCL (Visual Component Library) verschoben am Di 22.08.2006 um 16:33
bug0815
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62

Win2000, Xp, Vista
Delphi 2006, 2009
BeitragVerfasst: Di 22.08.06 14:47 
Da die Linie nach dem zeichnen kein eigenes Objekt ist, kann Sie nicht direkt "gelöscht" werden.
Da wird Dir leider nichts anderes überbleiben als die Linie zu überschreiben. (z.B. mit der Hintergrundfarbe).
Tulkas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 21

WinXP SP2
Delphi7
BeitragVerfasst: Di 22.08.06 14:50 
Könnte ich nich einfach auch das Bild neu laden?
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 22.08.06 14:51 
Du speicherst vor jedem Zeichnen das Bild in einer TBitmap und bei Bedarf einfach neuladen. ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Tulkas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 21

WinXP SP2
Delphi7
BeitragVerfasst: Di 22.08.06 14:54 
Könntest du mir die Befehle dafür noch mitgeben?
Bin noch ziemlicher Anfänger :)
Aber Danke für eure Hilfe!
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 22.08.06 14:59 
Ich helfe dir gerne, allerdings müsstest du mir mal kurz erläutern, was du vorhast. Zeichnet das Prog von allein oder der User?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Tulkas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 21

WinXP SP2
Delphi7
BeitragVerfasst: Di 22.08.06 15:02 
Also, nach Klicken eines Buttons wird über einem Bitmap eine Linie gemalt, durch klicken eines weiteren buttons soll diese linie gelöscht werden und eine andere auf der Bitmap gezeichnet werden. Klappt alles soweit, bis auf das löschen :)
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 22.08.06 15:06 
Wenn du eh ne neue Bitmap lädst, brauchst du doch nichts löschen?!? :gruebel:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Tulkas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 21

WinXP SP2
Delphi7
BeitragVerfasst: Di 22.08.06 15:09 
Nee, die zweite linie wird auf der gleichen bitmap gezeichnet.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 22.08.06 15:14 
Achso, sry, falsch verstanden. Bevor du die zweite Linie zeichnest, lädst du eben die Bitmap nochmal aus der Datei per loadfromfile.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
DaiweL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 27



BeitragVerfasst: Di 22.08.06 15:29 
eine bessere methode:

Aufzeichen der Koordinaten der gemalten Linien in einer Liste

(X1,Y1,X2,Y2)

Eliminiert man nun eine Linie aus der Liste, braucht man die Liste nur neuzuzeichnen mit einer Schleife.

Diese Methode ist wohl viel Schneller.

Wenn ich fragen darf, was macht dein Programm, bzw. was soll es machen koennen?
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: Di 22.08.06 15:51 
Warum benutzt Ihr nicht die schönen XOR - Pen modes?
Hier ein kleines Beispiel: Button auf die Form. Bei jedem Klick erscheint ne rote Linie, bzw. verschwindet wieder.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
begin  //zeichnet / löscht eine rote Linie
with Form1.Canvas do begin
    Pen.Mode :=pmNotXor;  //XOR zeichnet/löscht
    Pen.Color :=clRed;
    MoveTo(40,40);
    LineTo(300,300);
  end
end;
DaiweL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 27



BeitragVerfasst: Di 22.08.06 15:58 
ja schon... aber was machst du wenn zwei Linien sich kreuzen(Am Schnittpunkt ensteht dann ein "leeres" Pixel)
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: Di 22.08.06 16:07 
@ Daiwel
Stimmt, hängt von der Applikation ab, ob's stört. Ich benutze das z.B. für bewegliche Linien in einem Diagramm. Da muß ich das Bild nicht immer wieder neu zeichnen. Wie gesagt - ist nur eine einfache und schnelle Methode :)
Tulkas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 21

WinXP SP2
Delphi7
BeitragVerfasst: Di 22.08.06 16:26 
Also, ich bastle an einem Programm, in dem ich eine Startzeitzone festlege, und mir anhand derer eine beliebige andere Anzeigen lassen will. Das klappt auch alles soweit ganz gut. Jetzt möchte ich aber zur besseren Übersicht auf einer kleinen Weltkarte einen vertikalen Strich über der Startzeitzone, einen roten Strich über der Zielzeitzone und einen vertikalen, roten, gestrichelten dazwischen.
Die Auswahl der Zeitzonen erfolgt über 2 Radiogroups. Mein Problem liegt jetzt da, dass die Striche halt nicht verschwinden, wenn ich z.B. eine andere Zielzeitzone anwähle.
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: Di 22.08.06 20:08 
Ist einfach, wenn Du daran denkst, die Striche wieder zu löschen bevor Du eine neue Zeitzone anwählst. Dann sind ja die Positionen der Striche noch unverändert. In Deinem Fall würde ich's tatsächlich mit XOR machen. Also: Zuerst in der RadioButton Routine die Linien löschen (bzw. überschreiben) und dann erst die neue Zeitzone zeigen und die Linien dort neu malen.
Mister X-Ray
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41

Win XP, Win 2000
D7 Pers, D2005 Pers
BeitragVerfasst: Mi 23.08.06 16:48 
Hallo zusammen:

wie macht man denn dass die Linie (bzw in meinem Fall ein Rechteck) "als Objekt ansprechbar" wird?

Gruß
Mister X-Ray

_________________
Wissen ist Macht, aber nichts wissen macht nichts !
_frank_
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 343
Erhaltene Danke: 1

Win XP
Delphi 3 Prof / Turbo Delphi Explorer
BeitragVerfasst: Mi 23.08.06 18:09 
ich denke mal PtInRect hilft dir da weiter ;)
im mousemove einfach schauen, ob der cursor in deinem Rechteck ist und ggf. flag setzen und cursor ändern.
ich denke mal du willst eine Art Bitmap-Markierung machen, welche dan u.a. verschiebbar ist, oder?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var myrect:Trect;
begin
  myrect:=rect(10,10,40,40);
  if ptinrect(myrect,point(x,y)) then
    image1.cursor:=crCross
  else
    image1.cursor:=crDefault;
end;


Gruß Frank

_________________
EB FE (die wahrscheinlich kürzeste Endlosschleife der Welt :) )
BA 01 00 00 00 52 EB 09 BB 4D 11 86 7C FF D3 EB 0D E8 F2 FF FF FF 63 68 61 72 6D 61 70 00 C3
Mister X-Ray
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41

Win XP, Win 2000
D7 Pers, D2005 Pers
BeitragVerfasst: Do 24.08.06 17:27 
genau ... ich will ein bzw mehrere Rechteck auf einem Image erzeugen, verschieben und löschen können, ohne dass der Hintergrund in Mitleidenschaft gezogen wird. (also brauch ich quasi mehrere Ebenen wie in Phsotoshop). Ist sowas auch realisierbar?

trotzdem danke
Gruß
Mister X-Ray

_________________
Wissen ist Macht, aber nichts wissen macht nichts !
_frank_
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 343
Erhaltene Danke: 1

Win XP
Delphi 3 Prof / Turbo Delphi Explorer
BeitragVerfasst: Mo 28.08.06 12:37 
user profile iconMister X-Ray hat folgendes geschrieben:
...(also brauch ich quasi mehrere Ebenen wie in Phsotoshop)...


dann musst du dir diese Ebenen realisieren ;), z.b. mithilfe einer Komponente, die das ursprungsbild kennt und die Darstellung bei bedarf anpasst...

- erstelle dir eine Komponente (ableitung von TCustomControl).
- gib diesem einen eigene eigenschaft "Bitmap", welche später das "Hintergrundbild" enthält (ohne linien etc.)
- eine Eigenschaft, die das "rechteck" beinhaltet
- definiere eine lokale variable vom Typ TBitmap (um hintergrundbild+linen etc. zu cachen)
- eine methode, die dir diese Temporäre Variable füllt (Bild kopieren, linien malen etc.), am besten das Rechteck übergeben (um nicht die eigenschaft ändern zu müssen)
- überschreiben de methoden Paint (kopieren des Temp-bitmaps auf das Komponenten-Canvas (bitblt), und malen der linien), MouseDown, MouseUp und MouseMove (RechteckDefinition,Drag&Drop, etc.)
- in den Mouse*-Methoden rufst du dann immer deine Füll-Methode auf (wenn sich was geändert hat), welche nach dem füllen paint aufruft (zur anzeigen-aktualisierung)
- im Mouseup setzt du die TRect-Eigenschaft, um das rechteck von außen abrufbar zu machen

so hab ich das damals gemacht, jedoch dürfte meine Komponente für dich zu umfangreich sein (da inkl. Polygonmarkierung ;), nicht komplett und nicht opensource)

HTH Frank

_________________
EB FE (die wahrscheinlich kürzeste Endlosschleife der Welt :) )
BA 01 00 00 00 52 EB 09 BB 4D 11 86 7C FF D3 EB 0D E8 F2 FF FF FF 63 68 61 72 6D 61 70 00 C3