在 C# 中将带有背景图像的图像保存到文件中
我的表单上有一个图片框,BackgroundImage 属性设置为特定图像。图像的其余部分具有某些透明区域,以便在这些区域中显示背景图像。我想将其保存到文件中,但图片框没有保存方法。 image属性有一个save方法,但是它只保存图像的内容,不包括背景图像。有关如何保存两者的任何提示,以便它在文件中的外观与图片框上的外观完全相同?
I have a picturebox on the form, with BackgroundImage property set to certain image. The rest of the image has certain transparent areas, so that background image is shown in those areas. I want to save it to the file, but there is no save method for picturebox. There is a save method for image property, but then it only saves the content of the image, and does not include the backgroundimage. Any hints on how I can save both, so that it looks in the file exactly as it looks on the picturebox?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
编辑:
然后使用Graphics的drawImage方法绘制背景和前景并保存位图。
Try:
edit:
Then use the drawImage method of Graphics to draw background and foreground and save the bitmap.
我已经成功地通过使用图形将两个图像组合在一起,然后将结果保存为单个图像对象来实现此目的。因此,我不再使用背景图像。
I have managed to accomplish this by simply combining two images together using graphics, and then saving the result as a single image object. Thus, I am not using background image anymore.
g.DrawLine(myPen, EX, EY, eX, eY);
EX = eX;
EY = eY;<代码>
DrawArea = (位图)pictureBox1.Image.Clone();
pictureBox1.Image = DrawArea;
g.DrawLine(myPen, EX, EY, e.X, e.Y);
EX = e.X;
EY = e.Y;
DrawArea = (Bitmap)pictureBox1.Image.Clone();
pictureBox1.Image = DrawArea;