首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >放大屏幕的特定区域

放大屏幕的特定区域
EN

Stack Overflow用户
提问于 2012-08-16 19:43:46
回答 1查看 5.8K关注 0票数 1

我正在使用C#制作一个百叶窗工具。就像这个:http://colorsnapper.com,我已经搜索了整个谷歌,寻找一种方式放大一个预定义的屏幕区域,足以查看每一个像素。

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

有没有人知道我可以这样做,或者任何可用的API。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-16 19:49:55

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

代码语言:javascript
复制
/// <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 at×50 at矩形:

代码语言:javascript
复制
portionOf = bitmap.Clone(new Rectangle(pointer.X - 25, pointer.Y - 25, 50, 50), PixelFormat.Format32bppRgb);

并以鼠标位置为中心的100 in矩形以100 in显示它。这会给你一个2倍的变焦级别。(显示大小)/(捕获大小)的比率越大,缩放的范围就越大。与…有关的东西:

代码语言:javascript
复制
[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);
}
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11994331

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档