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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

keithcslAuthor Commented:
Edited text of question.
0
simonetCommented:

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

Alex
0
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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
AlphomegaCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.