Ste*_*eve 44
您可以尝试使用此方法保存图像
SaveFileDialog dialog = new SaveFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
int width = Convert.ToInt32(drawImage.Width);
int height = Convert.ToInt32(drawImage.Height);
Bitmap bmp = new Bitmap(width,height);
drawImage.DrawToBitmap(bmp, new Rectangle(0, 0, width, height);
bmp.Save(dialog.FileName, ImageFormat.Jpeg);
}
Run Code Online (Sandbox Code Playgroud)
Agh*_*oub 30
您可以尝试使用此代码
Image.Save("myfile.png",ImageFormat.Png)
Run Code Online (Sandbox Code Playgroud)
链接:http://msdn.microsoft.com/en-us/library/ms142147.aspx
如果您正在控件的图形上绘图,那么您应该在位图上绘制您在画布上绘制的所有内容,但请记住,位图需要是您正在绘制的控件的精确大小:
Bitmap bmp = new Bitmap(myControl.ClientRectangle.Width,myControl.ClientRectangle.Height);
Graphics gBmp = Graphics.FromImage(bmp);
gBmp.DrawEverything(); //this is your code for drawing
gBmp.Dispose();
bmp.Save("image.png", ImageFormat.Png);
Run Code Online (Sandbox Code Playgroud)
或者你可以使用DrawToBitmapControl的方法。像这样的东西:
Bitmap bmp = new Bitmap(myControl.ClientRectangle.Width, myControl.ClientRectangle.Height);
myControl.DrawToBitmap(bmp,new Rectangle(0,0,bmp.Width,bmp.Height));
bmp.Save("image.png", ImageFormat.Png);
Run Code Online (Sandbox Code Playgroud)