如何将图像转换为图形?将图像转换为图形在c#
回答
你需要的图片,以吸引你的图形,所以你可能已经拥有了像:
Graphics g = Graphics.FromImage(image);
如果你在一个控制的图形直接绘制,你可以创建一个新的位图与控件相同的尺寸,然后调用Control.DrawToBitmap()。然而,更好的方法通常是从一个位图开始,绘制到其图形上(如Darin所建议的),然后将位图绘制到控件上。
由于Graphics
对象不包含任何图像数据,因此无法将Graphics
对象转换为图像。
Graphics
对象只是一个用于在画布上绘制的工具。该画布通常是Bitmap
对象或屏幕。
如果Graphics
对象用于在Bitmap
上绘图,那么您已经拥有该图像。如果使用Graphics
对象在屏幕上绘图,则必须进行屏幕截图以获取画布图像。
如果Graphics
对象是从一个窗口控件创建,您可以使用控件的方法DrawToBitmap
渲染图像上,而不是屏幕上的控制。
谢谢您的回答 – 2010-05-23 15:41:26
和你解释 – 2010-05-23 15:43:32
@Sorush:我修好了它。 (为了将来的参考,如果你打算评论,以便Hesam会得到通知,你应该对问题发表评论,而不是回答。) – Guffa 2010-05-25 12:57:49
由于达林说,你可能已经有了这个形象。如果不这样做,你可以创建一个新的,并绘制到一个
Image bmp = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(bmp)) {
// draw in bmp using g
}
bmp.Save(filename);
Save图像保存到硬盘驱动器上的文件。
感谢您的回答 – 2010-05-23 15:44:46
把图形转换成位图的最好方法是摆脱了“使用”的东西:
Bitmap b1 = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(b1);
g.CopyFromScreen(0, 0, Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
b1.Save("screen.bmp");
我发现这一点的同时搞清楚如何将图形转换成位图,它就像一个魅力。
我对如何使用这一些例子:
//1. Take a screenshot
Bitmap b1 = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(b1);
g.CopyFromScreen(0, 0, Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
b1.Save("screen.bmp");
//2. Create pixels (stars) at a custom resolution, changing constantly like stars
private void timer1_Tick(object sender, EventArgs e)
{
/*
* Steps to use this code:
* 1. Create new form
* 2. Set form properties to match the settings below:
* AutoSize = true
* AutoSizeMode = GrowAndShrink
* MaximizeBox = false
* MinimizeBox = false
* ShowIcon = false;
*
* 3. Create picture box with these properties:
* Dock = Fill
*
*/
//<Definitions>
Size imageSize = new Size(400, 400);
int minimumStars = 600;
int maximumStars = 800;
//</Definitions>
Random r = new Random();
Bitmap b1 = new Bitmap(imageSize.Width, imageSize.Height);
Graphics g = Graphics.FromImage(b1);
g.Clear(Color.Black);
for (int i = 0; i <r.Next(minimumStars, maximumStars); i++)
{
int x = r.Next(1, imageSize.Width);
int y = r.Next(1, imageSize.Height);
b1.SetPixel(x, y, Color.WhiteSmoke);
}
pictureBox1.Image = b1;
}
有了这个代码,您可以使用所有的图形类的命令,并将其复制到一个位图,因此,让您保存任何设计与图形类。
您可能会使用这个优势。
- 1. 将方形图像转换为矩形
- 2. PHP - 如何将矩形图像转换为方形图像?
- 3. 将Java转换为C# - 创建图像并获取图形
- 4. 使用目标将矩形图像转换为方形图像c
- 5. 将矩形图像转换成梯形
- 6. 如何将图像转换为图像的ASCII表示形式?
- 7. 如何将fish_eye图像转换为平面矩形图像?
- 8. 将base64转换为c中的图像#
- 9. 将PDF转换为图像序列C#
- 10. 将mht转换为图像C#
- 11. 如何将图像转换为C#base64string
- 12. C#:如何将.pptx转换为图像?
- 13. 使用C#将图像转换为SVG
- 14. 将图像Python代码转换为C#
- 15. C#将XtraGrid转换为图像
- 16. 如何在OpenCV中将平行四边形图像转换为矩形图像?
- 17. C#转换为.ppt图像
- 18. 将图像转换为灰度图像
- 19. 将图像URL转换为图像Android
- 20. 将PIL图像转换为VIPS图像
- 21. 将图像转换为色度图像
- 22. 将.png图像转换为.gif图像
- 23. 将yuv文件转换为C#形式的图像
- 24. 将折线图转换为条形图
- 25. 将图像转换为流
- 26. 将varbinary转换为图像
- 27. 将图像转换为DrawingImage
- 28. 将图像转换为ushort?[]
- 29. 将BufferedInputStream转换为图像
- 30. 将Swf转换为图像
谢谢你的回答 – 2010-05-23 15:42:26
谢谢您的回答 – 2010-05-23 15:42:43
这是问题的相反的情况:问题是:图形到图像,不形象的图形,你回答 – 2017-08-24 06:33:31