0

我想在 RealBasic 中创建一个屏幕放大镜,但看不到任何用于读取屏幕区域的类或 API,然后我可以渲染到我的窗口。

任何事物?

附带问题:如果我无法读取整个区域,我是否可以至少进行逐像素读取来模拟读取光标下像素颜色的吸管工具?

4

2 回答 2

2

Realbasic有几种方法可以同时制作放大镜和滴管(无耻插件:我前段时间在RealBasic中写了一个滴管。)很简单,只需使用System.MouseXSystem调用System.Pixel函数即可.MouseY作为其参数。System.Pixel返回与您指定的屏幕坐标处的像素颜色相对应的颜色。

使用此颜色信息,您可以(显然)通过绘制到 Picture 对象或 Canvas 控件(如使用吸管)以更大的比例显示颜色。

这种方法可以用于放大镜之类的东西,但可能不应该。在 RealBasic 中逐个像素地绘制可能会很慢,这对于像放大镜这样的实时任务会导致性能问题和闪烁。

在 Windows 下,可能在 Mac OS X 和 GTK+ 下,有一些 API 函数允许您捕获屏幕区域,这对于屏幕截图和使用许多标准算法处理位图图像很有用。

这是一个简单的函数,它调用 Windows API 来捕获屏幕的 800x600 部分,将其放大 3 倍,然后将其复制到 Picture 对象中:

 Function GetZoomedPic() As Picture
  Declare Function GetDesktopWindow Lib "User32" () As Integer
  Declare Function GetDC Lib "User32" (HWND As Integer) As Integer
  Declare Function StretchBlt Lib "GDI32" (destDC As Integer, destX As Integer, destY As Integer, destWidth As Integer, destHeight As Integer, _
  sourceDC As Integer, sourceX As Integer, sourceY As Integer, sourceWidth As Integer, sourceHeight As Integer, rasterOp As Integer) As Boolean
  Declare Function ReleaseDC Lib "User32" (HWND As Integer, DC As Integer) As Integer

  Const CAPTUREBLT = &h40000000
  Const SRCCOPY = &HCC0020
  Dim coordx, coordy As Integer
  Dim magnifyLvl As Integer = 3
  Dim screenCap As New Picture(800, 600, 32)
  coordx = System.MouseX - (screenCap.Width \ (magnifyLvl * 2))
  coordy = System.Mousey - (screenCap.Height \ (magnifyLvl * 2))
  Dim rectWidth, rectHeight As Integer
  rectWidth = screenCap.Width \ magnifyLvl
  rectHeight = screenCap.Height \ magnifyLvl

  Dim deskHWND As Integer = GetDesktopWindow()
  Dim deskHDC As Integer = GetDC(deskHWND)
  Call StretchBlt(screenCap.Graphics.Handle(1), 0, 0, screenCap.Width, screenCap.Height, DeskHDC, coordx, coordy, rectWidth, _
  rectHeight, SRCCOPY Or CAPTUREBLT)
  Call ReleaseDC(DeskHWND, deskHDC)

  Return screenCap
End Function

大约在我写滴管的同时,我还写了一个基本的放大镜项目。您可以在此处下载项目文件。除了演示上述功能外,它还可以作为一个基本演示,演示如何在不闪烁的情况下绘制到画布、使用带有 Windows GDI 设备上下文的 RealBasic 图片对象以及使用线程从主线程中卸载工作。

于 2011-11-14T13:56:40.997 回答
1

看看 Real Software 论坛上关于这个主题的这个帖子。看起来您可以尝试多种解决方案。

http://forums.realsoftware.com/viewtopic.php?f=10&t=7818&hilit=screen+magnifier

于 2011-11-13T22:00:25.847 回答