我想知道Graphics对象正在绘制一些东西的缓冲区的中间状态是什么。如何获取位图或它正在绘制的图像?
发布于 2011-03-15 14:58:50
我不太确定我是否理解你的要求,因为你的问题很不清楚。
如果您想知道如何保存Graphics
对象转换为位图,那么答案是没有直接的方法可以做到这一点。在Graphics
对象是单向操作。
更好的选择是创建一个新的Bitmap
对象,则获取一个Graphics
对象,并直接在其上绘制。下面的代码是一个示例,说明了如何做到这一点:
// Create a new bitmap object
using (Bitmap bmp = new Bitmap(200, 300))
{
// Obtain a Graphics object from that bitmap
using (Graphics g = Graphics.FromImage(bmp))
{
// Draw onto the bitmap here
// ....
g.DrawRectangle(Pens.Red, 10, 10, 50, 50);
}
// Save the bitmap to a file on disk, or do whatever else with it
// ...
bmp.Save("C:\\MyImage.bmp");
}
https://stackoverflow.com/questions/5308363
复制相似问题