优化拾色器

This commit is contained in:
liufei
2022-05-23 17:52:35 +08:00
parent 09ab951ccd
commit ddabf0a113
6 changed files with 67 additions and 44 deletions

View File

@@ -66,16 +66,13 @@ namespace GeekDesk.Control.Windows
bgBitmap.Size
);
}
BitmapSource bs = Imaging.CreateBitmapSourceFromHBitmap(
bgBitmap.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions()
);
ImageBrush ib = (ImageBrush)DesktopBG.Background;
ib.ImageSource = bs;
DesktopBG.Source = bs;
VisualBrush b = (VisualBrush)PixelBG.Fill;
b.Visual = DesktopBG;
Mouse.OverrideCursor = Cursors.Cross;
@@ -83,10 +80,6 @@ namespace GeekDesk.Control.Windows
}
[DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern int BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);
public void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
@@ -98,13 +91,13 @@ namespace GeekDesk.Control.Windows
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Mouse.OverrideCursor = null;
Point pos = e.MouseDevice.GetPosition(DesktopBG);
System.Drawing.Color colorD = bgBitmap.GetPixel((int)pos.X, (int)pos.Y);
colorPicker.SelectedBrush = new SolidColorBrush(Color.FromArgb(colorD.A, colorD.R, colorD.G, colorD.B));
DeleteObject(bgBitmap.GetHbitmap());
this.Close();
ClickColorPickerToggleButton(colorPicker);
}
public void ClickColorPickerToggleButton(ColorPicker colorPicker)
@@ -121,13 +114,7 @@ namespace GeekDesk.Control.Windows
mi.Invoke(colorPicker, new object[] { null, null });
}
}
private void Window_MouseEnter(object sender, MouseEventArgs e)
{
Mouse.OverrideCursor = Cursors.Cross;
}
private void Window_PreviewMouseMove(object sender, MouseEventArgs e)
{
SetPixelAbout(e);