C# 将图形对象转换为位图对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1535730/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:31:02  来源:igfitidea点击:

Convert graphics object to bitmap object

c#graphicsbitmap

提问by Binu

How can I convert graphics object to bitmap object using C#?

如何使用 C# 将图形对象转换为位图对象?

回答by AndreyAkinshin

Bitmap myBitmap = new Bitmap(width, height, myGraphics);

Alternatively:

或者:

Graphics myGraphics = Graphics.FromImage(myBitmap);
// some code with draw on myGraphics
myGraphics.Dispose();

回答by Andrew Keith

Do you mean System.Drawing.Graphics? The Graphics class is a surface to an image and is already a bitmap.

你的意思是System.Drawing.Graphics?Graphics 类是图像的表面,并且已经是位图。

What are you trying to do with it ?

你想用它做什么?

using(Graphics g = Graphics.FromImage(bitmap))
{
  //draw here
}

or

或者

Bitmap bmp = new Bitmap(100,100,graphics);

回答by monksy

This looks like what you might want: DaniWeb, yes annoyingware but it does provide a working solution

这看起来像您可能想要的:DaniWeb,是的,烦人的软件,但它确实提供了一个可行的解决方案