保存System.Drawing.Graphics为PNG或BMP [英] Saving System.Drawing.Graphics to a png or bmp
问题描述
我有一个图形对象,我已经绘制在屏幕上,我需要将其保存为PNG或BMP文件。显卡似乎并不直接支持,但它必须能够以某种方式。
I have a Graphics object that I've drawn on the screen and I need to save it to a png or bmp file. Graphics doesn't seem to support that directly, but it must be possible somehow.
哪些步骤?
推荐答案
将其复制到位图
,然后调用位图的保存
方法。
Copy it to a Bitmap
and then call the bitmap's Save
method.
请注意,如果你的的字面的绘制到屏幕(通过抓取屏幕的设备上下文),那么唯一的办法救你刚才画的屏幕是通过绘制的逆过程从的屏幕的到的一个位图
。这是可能的,但它显然是一个更容易只是直接绘制到一个位图(使用相同的code用来绘制到屏幕)。
Note that if you're literally drawing to the screen (by grabbing the screen's device context), then the only way to save what you just drew to the screen is to reverse the process by drawing from the screen to a Bitmap
. This is possible, but it would obviously be a lot easier to just draw directly to a Bitmap (using the same code you use to draw to the screen).
这篇关于保存System.Drawing.Graphics为PNG或BMP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!