在C#winforms中保存SizeMode=stretch的用户绘制的PictureBox中的图像
我在图片框上绘制了一幅处于拉伸模式的图像,我通过使用一个函数来转换鼠标单击事件上的鼠标坐标,以获得真实坐标,并通过覆盖on paint事件和使用paint事件图形来绘制图像。 由于图片框设置为“拉伸”,当我尝试使用在C#winforms中保存SizeMode=stretch的用户绘制的PictureBox中的图像,c#,winforms,graphics,drawing,gdi+,C#,Winforms,Graphics,Drawing,Gdi+,我在图片框上绘制了一幅处于拉伸模式的图像,我通过使用一个函数来转换鼠标单击事件上的鼠标坐标,以获得真实坐标,并通过覆盖on paint事件和使用paint事件图形来绘制图像。 由于图片框设置为“拉伸”,当我尝试使用picturebox.DrawtoBitmap功能保存图像时,我只能获得一个小尺寸的图像。额外的部分用黑色填充。请帮助我。您可以尝试以下方法: using (Bitmap bmp = new Bitmap(pictureBox1.ClientSize.Width,
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);
}
您可以尝试以下方法:
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);
}
如果您知道如何将其绘制到图片框中,那么您就知道如何将其绘制到任何位图中。Graphics.ScaleTransform是您的朋友。如果您知道如何将其绘制到图片框中,那么您就知道如何将其绘制到任何位图中。Graphics.ScaleTransform是您的朋友。