日期:2014-05-19  浏览次数:20931 次

提问:如何得到WebBrowser中,某位置的像素的颜色?
我想取到WebBrowser显示的内容的某个坐标的像素值,试着这样写,
Bitmap   b   =   Bitmap.FromHbitmap(ie.CreateGraphics().GetHdc());
出错(GDI+   中发生一般性错误。)

请问正确的方法应该怎么样?

------解决方案--------------------
在WebBrowser这个控件里不可能只通过一个简单的Bitmap来操作,

或者你可以通过Graphics.CopyFromScreen 方法 把屏幕做为一个Bitmap来操作.
------解决方案--------------------
获取此 Bitmap 中指定像素的颜色。

命名空间:System.Drawing
程序集:System.Drawing(在 system.drawing.dll 中)

语法
Visual Basic(声明)
Public Function GetPixel ( _
x As Integer, _
y As Integer _
) As Color

Visual Basic(用法)
Dim instance As Bitmap
Dim x As Integer
Dim y As Integer
Dim returnValue As Color

returnValue = instance.GetPixel(x, y)

C#
public Color GetPixel (
int x,
int y
)

C++
public:
Color GetPixel (
int x,
int y
)

J#
public Color GetPixel (
int x,
int y
)

JScript
public function GetPixel (
x : int,
y : int
) : Color



参数
x
要检索的像素的 x 坐标。

y
要检索的像素的 y 坐标。


返回值
Color 结构,它表示指定像素的颜色。
------解决方案--------------------
private void button1_Click(object sender, EventArgs e)
{
Bitmap vBitmap = new Bitmap(webBrowser1.Width, webBrowser1.Height);
Graphics vGraphics = Graphics.FromImage(vBitmap);
vGraphics.CopyFromScreen(PointToScreen(webBrowser1.Location),
new Point(0, 0), new Size(vBitmap.Width, vBitmap.Height));

pictureBox1.Image = vBitmap;
}