繁体   English   中英

从用户绘制的PictureBox保存图像,该用户的PictureMode在C#winforms中为SizeMode = stretch

[英]Save Image from user Drawn PictureBox whose SizeMode=stretch in C# winforms

我在处于拉伸模式的图片框上绘制图像,我通过使用获取真实坐标的函数来转换鼠标单击事件上的鼠标坐标,并通过覆盖on-paint事件和使用paint事件Graphics来绘制图像。 由于将图片框设置为拉伸,因此当我尝试使用picturebox.DrawtoBitmap函数保存图像时,只能获得较小尺寸的图像。多余的部分用黑色填充。请帮帮我。

您可以尝试以下方法:

using (Bitmap bmp = new Bitmap(pictureBox1.ClientSize.Width,
                               pictureBox1.ClientSize.Height)) {
  using (Graphics g = Graphics.FromImage(bmp)) {
    g.DrawImage(yourBitmap,
                new Rectangle(0, 0, bmp.Width, bmp.Height),
                new Rectangle(0, 0, yourImage.Width, yourImage.Height),
                GraphicsUnit.Pixel);
  }
  bmp.Save(@"c:\yourfile.png", ImageFormat.Png);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM