2010-08-23 3 views
1

Как передать значения моей графики в растровое изображение, чтобы я мог сохранить его как файл jpg или bmp.Сохранить createGraphics в файле как изображение

вот мой код:

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]); 
      } 
     } 
    } 

предположить, что _listPS и _listPE имеют значения.

ах! Решила его LOL! :) Вот мое решение:

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(); 
     } 
    } 

ответ

1

Попробуйте один

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(); 
+0

же, как моя благодарность! :) – Rye

Смежные вопросы