将 System.Drawing.Graphics 保存为 png 或 bmp [英] Saving System.Drawing.Graphics to a png or bmp

查看:28
本文介绍了将 System.Drawing.Graphics 保存为 png 或 bmp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在屏幕上绘制了一个 Graphics 对象,我需要将其保存为 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.

步骤是什么?

推荐答案

将其复制到 Bitmap 中,然后调用该位图的 Save 方法.

Copy it to a Bitmap and then call the bitmap's Save method.

请注意,如果您字面上在屏幕上绘制(通过获取屏幕的设备上下文),那么保存您刚刚绘制到屏幕上的内容的唯一方法是通过绘制反转该过程屏幕一个Bitmap.这是可能的,但显然直接绘制到位图会容易得多(使用与绘制到屏幕相同的代码).

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屋!

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