Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 21st, 2005, 07:26 AM
DJ Supreme DJ Supreme is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 13 DJ Supreme User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 36 sec
Reputation Power: 0
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?

Reply With Quote
  #2  
Old October 22nd, 2005, 04:39 AM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 42 m 50 sec
Reputation Power: 185
Quote:
Originally Posted by DJ Supreme
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?

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.

Reply With Quote
  #3  
Old October 24th, 2005, 09:41 AM
DJ Supreme DJ Supreme is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 13 DJ Supreme User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 36 sec
Reputation Power: 0
Thank you

Reply With Quote
  #4  
Old October 26th, 2005, 07:00 AM
DJ Supreme DJ Supreme is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 13 DJ Supreme User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 36 sec
Reputation Power: 0
Quote:
Originally Posted by DJ Supreme
Thank you


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?

Reply With Quote
  #5  
Old November 1st, 2005, 04:15 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 42 m 50 sec
Reputation Power: 185
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > MS Paint like program


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT