如何更快速的抓取图片并在界面中显示图片?
本帖最后由 tanyinhua 于 2015-5-29 11:54 编辑RT,自己写了一个类似于放大镜的功能,把鼠标附近的区域截取下来,然后在界面中放大显示出来,但刷新速度非常慢,而且刷新的时候图象还一闪一闪的看的眼花,有办法让抓取图片更迅速,显示图片不闪一下吗?
还有,图象显示出来也好模糊,能像画图里放大那样清晰吗?
下面是我的代码,如果上面描述不清楚,看下代码就知道了。。
#include <ScreenCapture.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
HotKeySet("{ESC}", "Terminate")
HotKeySet("{F10}", "zuobiao")
HotKeySet("{UP}", "UP")
HotKeySet("{DOWN}", "DOWN")
HotKeySet("{LEFT}", "LEFT")
HotKeySet("{RIGHT}", "RIGHT")
Global $aPos
GUICreate("放大镜", 240, 240, -1, -1, $WS_SIZEBOX + $WS_SYSMENU) ; will create a dialog box that when displayed is centered
GUISetBkColor(0x000000)
WinMove("放大镜", "", 0, 0)
While 1
$aPos = MouseGetPos()
_ScreenCapture_Capture("C:\1.jpg", $aPos - 15, $aPos - 15, $aPos + 15, $aPos + 15)
Sleep(500)
GUICtrlCreatePic("C:\1.jpg", 0, 0, 240, 240)
GUISetState()
WEnd
Func zuobiao()
MsgBox(0, "鼠标坐标", $aPos & "," & $aPos)
EndFunc ;==>zuobiao
Func UP()
$aPos = MouseGetPos()
MouseMove($aPos, $aPos - 1, 0)
EndFunc ;==>UP
Func DOWN()
$aPos = MouseGetPos()
MouseMove($aPos, $aPos + 1, 0)
EndFunc ;==>DOWN
Func LEFT()
$aPos = MouseGetPos()
MouseMove($aPos - 1, $aPos, 0)
EndFunc ;==>LEFT
Func RIGHT()
$aPos = MouseGetPos()
MouseMove($aPos + 1, $aPos, 0)
EndFunc ;==>RIGHT
Func Terminate()
Exit 0
EndFunc ;==>Terminate 我在想有没有办法可以直接调用系统的放大镜。。
但系统的放大镜显示在屏幕上放,不能窗口显示不好用 自己顶啊。。 没人- -................ 有没有试过使用GDI+? 如果鼠標坐標沒改變~就不刷新畫面~
至少可以優化滑鼠靜置時~就不會一閃一閃了~ 另外...
Windows 7的放大鏡~
似乎有你需要的功能~
{:face (293):}
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$gui = GUICreate("",300,300)
GUISetState(@SW_SHOW) ; 显示一个空白的窗口
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
Global $hBitmap, $hImage
; 运行界面,直到窗口被关闭
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
GDI()
WEnd
; 清理资源
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_GraphicsDispose($hGraphic)
; 关闭 GDI+ 库
_GDIPlus_Shutdown()
Func gdi()
Local $mouse
$mouse = MouseGetPos()
; 捕获到 32 位位图
$hBitmap = _ScreenCapture_Capture("",$mouse - 10,$mouse - 10,$mouse + 10,$mouse + 10)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, 300, 300 )
EndFunc上面一个是按照您的思路来做的,下面一个是论坛里面别人发的放大镜,效果很棒。Global $pos, $var
Opt("PixelCoordMode", 0) ;;设置用于象素函数的坐标参照,相对当前激活窗口的坐标位置
Opt("MouseCoordMode", 0);;设置用于鼠标函数的坐标参照,可以是相对当前激活窗口的坐标位置
HotKeySet("{esc}", "leave")
HotKeySet("`", "shijian")
$hwd = GUICreate("主窗口", 200, 240, 0, 0, BitXOR(0x80880000, 0x00800000), 0x00000080 + 0x00000008)
GUICtrlCreateLabel("坐标颜色代码:", 12, 203, 90, 15)
$S = GUICtrlCreateInput("", 102, 201, 80, 18)
GUICtrlCreateLabel("相对X坐标:", 3, 223, 66, 16)
$X = GUICtrlCreateInput("", 63, 220, 30, 18)
GUICtrlCreateLabel("相对Y坐标:", 98, 223, 66, 16)
$Y = GUICtrlCreateInput("", 160, 220, 35, 18)
GUISetState()
While 1
Sleep(25)
MAG()
WEnd
Func MAG()
$MyHDC = DllCall("user32.dll", "int", "GetDC", "hwnd", $hwd)
If @error Then Return
$DeskHDC = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
If Not @error Then
$pos = MouseGetPos()
If Not @error Then
DllCall("gdi32.dll", "int", "StretchBlt", "int", $MyHDC, "int", 0, "int", 0, "int", 200, "int", 200, "int", $DeskHDC, "int", $pos - 25, "int", $pos - 25, "int", 50, "int", 50, "long", 0x00CC0020)
EndIf
DllCall("user32.dll", "int", "ReleaseDC", "int", $DeskHDC, "hwnd", 0)
EndIf
DllCall("user32.dll", "int", "ReleaseDC", "int", $MyHDC, "hwnd", $hwd)
Sleep(25)
$var = PixelGetColor($pos, $pos);;
GUICtrlSetData($X, $pos)
GUICtrlSetData($Y, $pos);;
GUICtrlSetData($S, "0x" & Hex($var, 6));;
GUICtrlSetBkColor($S, $var)
EndFunc ;==>MAG
Func leave()
Exit
EndFunc ;==>leave
Func shijian()
FileWrite(@DesktopDir & '\MOUSEPOS.LOG', @CRLF & '记录生成时间:' & @YEAR & '年' & @MON & '月' & @MDAY &'日' & _
' ' & @HOUR & '时' & @MIN & '分' & @SEC & '秒' & @CRLF & '鼠标X坐标:' & $pos & @CRLF & _
'鼠标Y坐标:' & $pos & @CRLF & '颜色代码:' & "0x" & Hex($var, 6) & @CRLF)
If MsgBox(262212, '选择', "保存成功,是否继续?") = 6 Then Return
Exit
EndFunc ;==>shijian
页:
[1]