如何在C#中涂板得到的位图 [英] How to get bitmap from painted panel in C#

查看:146
本文介绍了如何在C#中涂板得到的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小组,我使用它的图形克= panel1.CreateGraphics()画线和其他的东西。我需要的地方点击鼠标点的像素颜色,所以我决定用位图的GetPixel方法。我创建位图是这样的:

I have a panel and I use it's Graphics gr = panel1.CreateGraphics() to draw lines and other stuff. I need to get pixel color of the point where mouse is clicked, so I decided to use GetPixel method of Bitmap. I create bitmap this way:

Bitmap b = new Bitmap(width, height);            
panel1.DrawToBitmap(b, new Rectangle(0, 0, width, height));
b.Save("D:/aaa.bmp");

但我得到哪怕我画什么只有白色矩形。有什么问题?

but I get only white rectangle even if I've drawn anything. What's the problem?

推荐答案

只有在油漆活动将由 DrawToBitmap渲染绘制的东西。而不是显式调用 panel1.CreateGraphics(),处理面板的画图事件,并用做绘图 e.Graphics

Only things that are drawn in the Paint event will be rendered by DrawToBitmap. Instead of explicitly call panel1.CreateGraphics(), handle the Paint event of the panel and do your drawing using e.Graphics.

这篇关于如何在C#中涂板得到的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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