C# 将文件中的createGraphics另存为图像

C# 将文件中的createGraphics另存为图像,c#,gdi+,picturebox,paint,C#,Gdi+,Picturebox,Paint,如何将图形的值转换为位图,以便将其保存为jpg或bmp文件 这是我的密码: private void pictureBox1_Paint_1(object sender, PaintEventArgs e) { using(var p = new Pen(Color.Blue, 4)){ for (int i = 0; i < _listPS.Count; i++) { e.Graphics.Draw

如何将图形的值转换为位图,以便将其保存为jpg或bmp文件

这是我的密码:

private void pictureBox1_Paint_1(object sender, PaintEventArgs e)
    {
       using(var p = new Pen(Color.Blue, 4)){
           for (int i = 0; i < _listPS.Count; i++)
           {
            e.Graphics.DrawLine(_pen, _listPS[i], _listPE[i]);
           }
       }
    }
private void pictureBox1\u Paint\u 1(对象发送方,PaintEventArgs e)
{
使用(var p=新笔(颜色:蓝色,4)){
对于(int i=0;i<\u listPS.Count;i++)
{
e、 图形.抽绳(_pen,_listPS[i],_listPE[i]);
}
}
}
假设_listPS和_listPE有值

啊!!解决了,哈哈 以下是我的解决方案:

private Bitmap _mybitmap;
private void pictureBox1_Paint_1(object sender, PaintEventArgs e)
    {   
        _mybitmap = new Bitmap(pictureBox1.Width, pictureBox1.Heigth);
        Graphics _tempg = Graphics.FromImage(_mybitmap);

       using(var p = new Pen(Color.Blue, 4){
           for (int i = 0; i < _listPS.Count; i++)
           {
               e.Graphics.DrawLine(_pen, _listPS[i], _listPE[i]);
               _tempg.DrawLine(_pen, _listPS[i], _listPE[i]);
           }

           _tempg.Dispose();
        }
    }
私有位图\u mybitmap;
私有void pictureBox1_Paint_1(对象发送方,PaintEventArgs e)
{   
_mybitmap=新位图(pictureBox1.Width,pictureBox1.Heigth);
Graphics _tempg=Graphics.FromImage(_mybitmap);
使用(var p=新笔(颜色:蓝色,4){
对于(int i=0;i<\u listPS.Count;i++)
{
e、 图形.抽绳(_pen,_listPS[i],_listPE[i]);
_临时抽绳(_pen,_listPS[i],_listPE[i]);
}
_tempg.Dispose();
}
}
试试这个

Bitmap _image = new Bitmap(100, 100);
Graphics _g = Graphics.FromImage(_image);

//Graphics _g = pictureBox1.CreateGraphics();
Pen _pen = new Pen(Color.Red, 3);
Point myPoint1 = new Point(10, 20);
Point myPoint2 = new Point(30, 40);

for (int i = 0; i < _listPS.Count; i++)
{
    _g.DrawLine(_pen, _listPS[i], _listPE[i]);
}

_image.Save(@"D:\test.bmp");
_image.Dispose();
_g.Dispose();
Bitmap\u image=新位图(100100);
Graphics _g=Graphics.FromImage(_image);
//Graphics _g=pictureBox1.CreateGraphics();
钢笔=新钢笔(颜色:红色,3);
点myPoint1=新点(10,20);
点myPoint2=新点(30,40);
对于(int i=0;i<\u listPS.Count;i++)
{
_g、 抽绳(_pen,_listPS[i],_listPE[i]);
}
_image.Save(@“D:\test.bmp”);
_image.Dispose();
_g、 处置();
试试这个

Bitmap _image = new Bitmap(100, 100);
Graphics _g = Graphics.FromImage(_image);

//Graphics _g = pictureBox1.CreateGraphics();
Pen _pen = new Pen(Color.Red, 3);
Point myPoint1 = new Point(10, 20);
Point myPoint2 = new Point(30, 40);

for (int i = 0; i < _listPS.Count; i++)
{
    _g.DrawLine(_pen, _listPS[i], _listPE[i]);
}

_image.Save(@"D:\test.bmp");
_image.Dispose();
_g.Dispose();
Bitmap\u image=新位图(100100);
Graphics _g=Graphics.FromImage(_image);
//Graphics _g=pictureBox1.CreateGraphics();
钢笔=新钢笔(颜色:红色,3);
点myPoint1=新点(10,20);
点myPoint2=新点(30,40);
对于(int i=0;i<\u listPS.Count;i++)
{
_g、 抽绳(_pen,_listPS[i],_listPE[i]);
}
_image.Save(@“D:\test.bmp”);
_image.Dispose();
_g、 处置();