创建图形并将其另存为位图
我有两个问题:
1)我有一个 PictureBox
,它的 Dock 设置为 Fill。当我调整 Form
的大小时,我无法在扩展的 PictureBox
部分上创建图形。问题是什么?
2) 我想将 PictureBox
上创建的 Graphic 转换为 Bitmap
并将其另存为 *.JPG 或 *.bmp。我该怎么做?
I have two questions:
1) I have a PictureBox
and its Dock is set to Fill. When I resize the Form
I cannot create a Graphic on the part of the PictureBox
that is extended. What is the problem?
2) I want to convert the Graphic that is created on the PictureBox
to Bitmap
and save it as
*.JPG or *.bmp. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个,对我来说效果很好......
Try this, works fine for me...
1)你的描述很模糊。你有例外吗?是否显示错误的结果?怎么了?
2)您需要从 PictureBox 获取图像并使用其 保存方法。
1) Your description is very vague. Do you get an exception? Does it display wrong results? What is happening?
2) You need to get the Image from the PictureBox and use its Save method.
当调整 Picturebox 的大小以填充表单时,它的 Image 属性似乎保持不变。
因此,您需要做的是处理 PictureBox.OnSizeChanged 事件,然后使用以下代码来调整图像大小:
要保存图像,请使用:
希望有帮助!
When the Picturebox gets resized to fill the form, it seems it's Image property stays the same.
So what you need to do is handle the PictureBox.OnSizeChanged Event, and then use the following code to resize the image:
To save the image use:
Hope that helps!
您可以使用手柄设备从图片框中获取位图
甚至更好的是,如果pictureBox不修改图像,您可以直接从pictureBox控件获取图像
you can use the handle device to get the bitmap out of the picture box
or even better, if the pictureBox does`nt modify the image, you can directly get the image from the pictureBox control