将图形转换为位图

时间:2009-10-08 05:17:43

标签: c# .net drawing bitmap

我正在创建一个Graphics对象来绘制原始图像,我希望将修改后的图像保存为新图像。表单上的图像以及图形

2 个答案:

答案 0 :(得分:1)

 //load bitmap from file
 Image bmp = Image.FromFile();

Graphics g = Graphics.FromImage(bmp);

//do drawing here with g.

bmp.Save();

g.Dispose()

答案 1 :(得分:1)

    Bitmap newBitmap = new Bitmap(originalBitmap);
    using (Graphics myGraphics = Graphics.FromImage(newBitmap))
    {
        // draw here on myGraphics
    }
    // newBitmap - modified image

或者使用Load&保存:

    Bitmap myBitmap = new Bitmap("fileName.bmp");
    using (Graphics myGraphics = Graphics.FromImage(myBitmap))
    {
        // draw here on myGraphics
    }
    myBitmap.Save("newFileName.bmp");