poligon on a bitmap...

hi all

i have a TImage with a bitmap loaded on it. Now i need to draw a poligon on top of the bitmap.

The functionality is exactly the same as MS Paint, where you load in a bitmap and select the poligon tool and start drawing.

My problem is:

in the OnMouseMove event, i am using

LineTo(NewX, NewY);

to give the user a preview of where the new line is going to be. however, I need to clear the previous preview line and draw the new one. how does MS Paint do it? It is almost like I need an UndoLine method.

I could write an UndoLine method, but how do i then specify a clear color to clear the previous line?

i must be using a too difficult approach.

Stumped.
Keith


LVL 1
keithcslAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
AlphomegaConnect With a Mentor Commented:
Hi,

To do that, you need:

implementation

var

P1, P2: TPoint;

procedure TForm1.Create;
begin
 image1.canvas.Pen.mode := pmNotMerge;
end;

procedure TForm1.Image1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 P1.x := x;
 P1.y := y;
 P2 := P1;
 Image1.canvas.polyline([P1, P2]);
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
 if ssleft in shift then
 begin
  Image1.canvas.polyline([P1, P2]);
  P2 := Point(X, Y);
  Image1.canvas.polyline([P1, P2]);
 end;
end;

0
 
keithcslAuthor Commented:
Edited text of question.
0
 
simonetCommented:

Have you tried using the Canvas object of the TBitmap (or TImage) ?

Alex
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
interCommented:
hi,

just set Canvas.Pen.Mode := pmXor when user starts selecting. then on each move draw the line on old coordinates which erases the line since you are doing Xor.

regards, igor
0
 
keithcslAuthor Commented:
inter

if the line is drawn as black, pmXor in the next redraw will not bring the orginal background color back.

i have tried setting the Mode to pmNOT. this will set the line to NOT of the background. then when i redraw the line, it NOTs it back to the background color.

this works, but it is not desireable. i want to draw it with a black line.

Keith
0
 
keithcslAuthor Commented:
Alphomega

your method seems to be giving me the same results as mine. it is not drawing the line in black, instead it is Not'ing the background color.

i tried MS Paint and it does it perfectly, nice black line.

hmmmm... maybe i need to store the background pixel values?

Keith
0
 
interCommented:
the you should have override the WMPaint method. Each time invalidated draw your poly line including the one user dragging in one place.
0
 
AlphomegaCommented:
Sorry, but I think that if you want to get a black line, there is no possibility except to save a region on bitmap. Each time you draw a line, you save the pixels array and redraw in the following call.

0
 
keithcslAuthor Commented:
Alphomega

thanks for all ur help. i know which to go from here...

regards
Keith
0
All Courses

From novice to tech pro — start learning today.