保存来自用户绘制的PictureBox的图像,其SizeMode =在C#winforms中拉伸 [英] Save Image from user Drawn PictureBox whose SizeMode=stretch in C# winforms

查看:246
本文介绍了保存来自用户绘制的PictureBox的图像,其SizeMode =在C#winforms中拉伸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在拉伸模式下的图片框上绘制图像时,我通过使用函数来获取真实坐标并在鼠标单击事件上转换鼠标坐标,并通过覆盖绘图事件并使用绘画来绘制图像事件图形。
由于图片框设置为拉伸,因此当我尝试使用 picturebox.DrawtoBitmap 函数来保存图片时,只能获取小尺寸的图片。填充黑色colour.Please帮助我。

Im drawing an image on picture box which is in stretch mode,I translate the mouse coordinates on the mouse click event by using a function to obtain the real coordinates and draw the image by overriding the on-paint event and using the paint event Graphics. Since the picture box is set to stretch i only obtain a small size image when i try to save the image by using picturebox.DrawtoBitmap Function.The extra parts are padded with Black colour.Please help me out.

推荐答案

您可以试试这个:

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

这篇关于保存来自用户绘制的PictureBox的图像,其SizeMode =在C#winforms中拉伸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆