# [.net] Im trying to make an image editor

This topic is 4043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Can someone point me to references I must read on, or sample codes maybe? I am, so far, still confused on how to properly use the System::Drawing namespace. I need something to start with, like, drawing a line across an existing bitmap. Hehe, I am such a newb to this stuff.

##### Share on other sites
You'd normally use a Graphics object to handle this. You can create one for an existing Bitmap using the Graphics.FromImage method.

To draw a line, you could do this:

Bitmap B = new Bitmap(100, 100);Graphics G = Graphics.FromImage(B);G.Clear(Color.Red);G.DrawLine(Pens.Blue, 0, 0, 100, 100);B.Save("Picture.png");

There are various properties of the Graphics object that control the quality of the drawing. Graphics.SmoothingMode, for example, controls antialiasing (so setting it to HighQuality draws very nice smooth lines).

The only one I can think of that might cause confusion is Graphics.PixelOffsetMode. By default, if you draw something inside pixel (0,0) it is drawn as if (0,0) is in the centre of the top-left pixel, rather than the more intuitive top-left corner. Set it to Half to offset it backwards (-.5,-.5). The most obvious test of this is to use Graphics.DrawImage with integer coordinates - it looks rather blurry with the default settings.

Graphics.Transform can be used to transform what you're drawing, for all sorts of interesting rotation and scaling effects.

[Edited by - benryves on January 26, 2007 9:04:19 AM]

##### Share on other sites
When you are up to it, take a look at the source code for Paint .NET: http://www.getpaint.net/download.html

##### Share on other sites
Great! Thank you very much!