2011-11-13 49 views
0

我想在RealBasic中創建一個屏幕放大鏡,但沒有看到任何用於讀取屏幕區域的類或API,然後我可以渲染到我的窗口。我可以在RealBasic中編寫屏幕放大鏡嗎?

什麼?如果我不能讀取整個區域,我是否至少可以做每個像素的讀數來模擬一個讀取光標下像素顏色的吸睛工具?

回答

2

有幾種方法,既放大鏡和滴管可以與REALbasic中進行(無恥插頭:我前一段時間寫了一個eyedropper in RealBasic)這很簡單,只用調用System.Pixel功能System.MouseXSystem.MouseY作爲其參數。 System.Pixel返回顏色對應於您指定的屏幕座標處像素的顏色。

隨着通過繪製爲圖片對象或畫布控制可以(顯然)示出了在較大規模的顏色這個顏色信息(與滴管。)

此方法可用於像一個放大鏡,但可能不應該。在RealBasic中逐個像素地繪製可能會很慢,而像放大鏡這樣的實時任務會導致性能問題和閃爍。

在Windows下,可能在Mac OS X和GTK +下,有API函數可以捕獲屏幕區域,這對截圖非常有用,並且可以使用多種標準算法處理位圖圖像。

這裏是一個調用Windows API一個簡單的功能來捕捉屏幕的800x600的部分,由3放大它,並將其複製到一個圖片對象:

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 

大約在同一時間,我寫的吸管,我也寫了一個基本的放大鏡項目。您可以下載項目文件here。除了演示上述功能之外,它還可以作爲繪製畫布而不閃爍的基本演示,在Windows GDI設備上下文中使用RealBasic Picture對象以及使用線程從主線程卸載工作。

+0

正是我在找的東西。謝謝!現在另一個問題......(理解我還沒有下載演示,因爲我不想浪費我的時間,如果這不能完成......)你展示瞭如何通過Windows來做到這一點,但我的當然希望這是跨平臺的,因此即使考慮RS/RB。我如何指出「編譯Windows時,使用'x',但編譯Mac時使用'Y'。」如果你可以更新你的例子,即使是用Mac方面的人爲調用,那也太棒了! – MarqueIV

+0

在旁邊註釋... MAN這帶回了Win32編程的記憶! :) – MarqueIV

+0

Nev介意最後一個問題。看着你的代碼,我找到了我需要的東西。謝謝! :) – MarqueIV

相關問題