我如何获取一张图片的某一个像素点的颜色。
我可以获取PictureBox上的某一像素点的颜色。
代码如下:
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern int GetPixel (IntPtr hdc , int x1,int y1);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(IntPtr hdcDest,int nXDest,int nYDest,int nWidth,int nHeight,IntPtr hdcSrc,int nXSrc,int nYSrc,System.Int32 dwRop);
Graphics g = this.pictureBox1.CreateGraphics();
IntPtr dc2 = g.GetHdc();
int c1;
c1=GetPixel(dc2,10,10);
g.ReleaseHdc(dc2);
MessageBox.Show(c1.ToString());
但是我把Graphics g = this.pictureBox1.CreateGraphics();改为
Graphics gBack = Graphics.FromImage(pictureBox1.Image);后不管我如何更换pictureBox1的image,得出的结果都是789261。不知是为什么。请高手指点。谢谢。