[Solved] Making and drawing an image C#? [closed]


You could use GDI+ (and more specifically the Graphics class):

// Load an existing image into a Graphics object
using (var image = Image.FromFile(@"c:\work\input.png"))
using (var gfx = Graphics.FromImage(image))
{
    // Draw a line on this image from (0x0) to (50x50)
    gfx.DrawLine(new Pen(Color.Red), 0, 0, 50, 50);

    // save the resulting Graphics object to a new file
    using (var output = File.OpenWrite(@"c:\work\output.png"))
    {
        image.Save(output, ImageFormat.Png);
    }
}

UPDATE:

And if you want to create a new image:

// Create a new image 50x50 in size
using (var image = new Bitmap(50, 50))
using (var gfx = Graphics.FromImage(image))
{
    // Draw a line on this image from (0x0) to (50x50)
    gfx.DrawLine(new Pen(Color.Red), 0, 0, 50, 50);

    // save the resulting Graphics object to a new file
    using (var output = File.OpenWrite(@"c:\work\output.png"))
    {
        image.Save(output, ImageFormat.Png);
    }
}

3

solved Making and drawing an image C#? [closed]