我找到了解决方案!这里如果有人需要它!
[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);
}
而且我把这种方法是这样的:
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;
凡point
是我RightColorPanel
,我让我的颜色在具体点! 这个作品真的很棒!