|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
MS Paint like program
Whats the simplest way to make a Paint like app, i cant find any examples.
I mean, is it possible to draw using a brush, and change pen width etc with only a few lines of code? ![]() |
|
#2
|
|||
|
|||
|
Quote:
Yes. Windows supplies you with drawing canvases, brushes and pens. Delphi wraps them in the "Canvas" object. Put an empty TImage on a Form. Then start: Code:
with Image1.Picture.Bitmap.Canvas do begin // Prepare Brush and Pen Brush.Style:=bsSolid; Pen.Color:=clBlack; Pen.Size:=1; // Make Background white (fill with a white solid brush) Brush.Color:=clWhite; FillRect(Rect(0,0,Image1.Width,Image1.Height); // draw a 2px thick red line Pen.Color:=clRed; Pen.Size:=2; MoveTo(0,0); LineTo(Image1.Width, Image1.Height); // draw a 2px blue rectangle filled with green Pen.Color:=clBlue; Brush.Color:=clGreen; Rectangle(20,20,50, 50); end; HTH, M.
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#3
|
|||
|
|||
|
Thank you
|
|
#4
|
|||
|
|||
|
Quote:
Dodgee, when i try to paint on the canvas my image dissapears! ![]() So then i tried: Code:
procedure TfrmUltraViewer.imgMainMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
try
{Prepare Brush and Pen}
imgMain.Picture.Bitmap.Canvas.Brush.Style:= bsSolid;
imgMain.Picture.Bitmap.Canvas.Pen.Color:= clBlack;
{Begin Drawing}
imgMain.Picture.Bitmap.Canvas.Pixels[mouse.cursorpos.X,mouse.cursorpos.Y]:= imgMain.Picture.Bitmap.Canvas.Pen.Color;
finally
imgMain.Free;
end;
end;
May i download an example? |
|
#5
|
|||
|
|||
|
Umm. Where did my answer from last week go???
Anyways, your image disappears because it is not a bitmap. You probably loaded a JPG into the TImage. Try to load an empty bitmap instead. HTH, M. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > MS Paint like program |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|