将 createGraphics 保存为图像文件中
如何将图形的值传输到位图,以便将其保存为 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]);
}
}
}
假设 _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();
}
}
How can I transfer the values of my graphics to a bitmap so I can save it as jpg or bmp file.
here's my code:
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]);
}
}
}
suppose that _listPS and _listPE have values.
ah! Solved it LOL! :)
Here's my solution:
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
Try this one