【问题标题】:Save Image from user Drawn PictureBox whose SizeMode=stretch in C# winforms从 C# winforms 中 SizeMode=stretch 的用户绘制的 PictureBox 保存图像
【发布时间】:2012-01-02 23:15:10
【问题描述】:

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

【问题讨论】:

  • 如果您知道如何将其绘制到图片框中,那么您就知道如何将其绘制到any位图中。 Graphics.ScaleTransform 是你的朋友。

标签: c# winforms graphics drawing gdi+


【解决方案1】:

你可以试试这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-17
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多