I found the solution! Here it is if anyone need it!
[DllImport("gdi32")]
private static extern int GetPixel(int hdc, int nXPos, int nYPos);
[DllImport("user32")]
private static extern int GetWindowDC(int hwnd);
[DllImport("user32")]
private static extern int ReleaseDC(int hWnd, int hDC);
private static SolidColorBrush GetPixelColor(Point point)
{
int lDC = GetWindowDC(0);
int intColor = GetPixel(lDC, (int)point.X, (int)point.Y);
// Release the DC after getting the Color.
ReleaseDC(0, lDC);
byte a = (byte)( ( intColor >> 0x18 ) & 0xffL );
byte b = (byte)((intColor >> 0x10) & 0xffL);
byte g = (byte)((intColor >> 8) & 0xffL);
byte r = (byte)(intColor & 0xffL);
Color color = Color.FromRgb(r, g, b);
return new SolidColorBrush(color);
}
And I Call this method this way:
SolidColorBrush solidcolor = GetPixelColor(RightColorPanel.PointToScreen(point));
Color color = Color.FromArgb(solidcolor.Color.A,
solidcolor.Color.R,
solidcolor.Color.G,
solidcolor.Color.B);
LinearGradientBrush brush = new LinearGradientBrush();
brush.StartPoint = new Point(0, 0);
brush.EndPoint = new Point(1, 0);
brush.GradientStops.Add(new GradientStop(Colors.White, 0.0));
brush.GradientStops.Add(new GradientStop(color, 1));
MainColorPanel.Background = brush;
Where point
is the Specific Point of my RightColorPanel
that I keep my Colors at!
This works realy great!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…