创建图形并保存为位图 [英] Create graphic and save it as Bitmap

查看:135
本文介绍了创建图形并保存为位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个问题:

1)我有一个图片框和它的码头设置为填充。当我调整表格我无法在图片框被延长的部分创建一个图形。有什么问题?

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)我想转换是在图片框创建位图图形,并保存为
* .jpg或* .BMP。我怎样才能做到这一点?

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?

推荐答案

您可以使用手柄装置,以获得从位图图片框的

you can use the handle device to get the bitmap out of the picture box

Graphics g = pictureBox1.CreateGraphics();          
Bitmap bitMap = Bitmap.FromHbitmap(g.GetHdc());
bitMap.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);

甚至更好,如果图片框does`nt修改图像,你可以直接从PictureBox控件获得图像

or even better, if the pictureBox does`nt modify the image, you can directly get the image from the pictureBox control

pictureBox1.Image.Save("path", System.Drawing.Imaging.ImageFormat.Jpeg);

这篇关于创建图形并保存为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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