【问题标题】:Magnify a specific area of the screen [closed]放大屏幕的特定区域[关闭]
【发布时间】:2012-08-13 05:24:56
【问题描述】:

我正在使用 C# 制作放大镜工具。很像这个:http://colorsnapper.com 我在 Google 上搜索了一种方法来放大屏幕的预定义区域,足以查看每个单独的像素。

更具体地说,我希望我的鼠标成为屏幕上的放大镜,以增强鼠标悬停在上面的每个像素。我需要弄清楚如何放大该预定义区域。

有谁知道我可以做到这一点的方法,或者任何可用的 API。

更新 我找到了 Microsoft 提供的放大 API:http://msdn.microsoft.com/en-us/library/windows/desktop/ms692402(v=vs.85).aspx 但是,此 API 是 C++ 中的。正如我所收集的,C++ 是编写 Windows 操作系统的内容,要使用这个 API,我需要使用某种 C# 包装器。这不是一个问题,我只是想我会为其他用户添加到这篇文章中。

【问题讨论】:

  • 如果您的初始问题未能产生响应,您应该编辑它而不是发布新问题。

标签: c# .net zooming loupe magnify


【解决方案1】:

您可以将屏幕捕获到内存中的位图:

/// <summary>
/// Saves a picture of the screen to a bitmap image.
/// </summary>
/// <returns>The saved bitmap.</returns>
private Bitmap CaptureScreenShot()
{
    // get the bounding area of the screen containing (0,0)
    // remember in a multidisplay environment you don't know which display holds this point
    Rectangle bounds = Screen.GetBounds(Point.Empty);

    // create the bitmap to copy the screen shot to
    Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);

    // now copy the screen image to the graphics device from the bitmap
    using (Graphics gr = Graphics.FromImage(bitmap))
    {
           gr.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
    }

    return bitmap;
}

然后取图像的一部分,也许是一个以鼠标位置为中心的 50 像素 x 50 像素的矩形:

portionOf = bitmap.Clone(new Rectangle(pointer.X - 25, pointer.Y - 25, 50, 50), PixelFormat.Format32bppRgb);

并将其显示在以鼠标位置为中心的 100 像素 x 100 像素的矩形中。这将为您提供 2X 缩放级别。 (显示大小)/(捕获大小)的比率越大,缩放越多。大致如下:

[DllImport("User32.dll")]
public static extern IntPtr GetDC(IntPtr hwnd);

[DllImport("User32.dll")]
public static extern void ReleaseDC(IntPtr hwnd, IntPtr dc);

void OnPaint()
{
    IntPtr desktopDC = GetDC(IntPtr.Zero); // Get the full screen DC

    Graphics g = Graphics.FromHdc(desktopDC); // Get the full screen GFX device

    g.DrawImage(portionOf, pointer.X - 50, pointer.Y - 50, 100, 100); // Render the image

    // Clean up
    g.Dispose();
    ReleaseDC(IntPtr.Zero, desktopDC);
}

【讨论】:

  • 给男人一条鱼...等等,不,OP只是继承了加工厂。
猜你喜欢
  • 1970-01-01
  • 2016-04-06
  • 1970-01-01
  • 2015-03-23
  • 2013-08-12
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 2014-01-07
相关资源
最近更新 更多