Loken Posted July 30, 2016 Share Posted July 30, 2016 Hello forum, I'm using a script to draw images on gui. Script draws an image 40 ms between 80 ms. How can i speed up this process? Here is my code below; #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> $Width = @DesktopWidth/5 $Height = @DesktopHeight/5 $Form = GUICreate("GUI", $Width, $Height, -1, -1) $Pic= GUICtrlCreatePic("", 0, 0, $Width, $Height) GUISetState(@SW_SHOW) $hCtrl = GUICtrlGetHandle($Pic) _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hCtrl) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch $Timer = TimerInit() $hBMP = _ScreenCapture_Capture("") $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $Width, $Height) _GDIPlus_BitmapDispose($hBitmap) _WinAPI_DeleteObject($hBMP) ToolTip(TimerDiff($Timer)) WEnd _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Thanks. Link to comment Share on other sites More sharing options...
InunoTaishou Posted July 30, 2016 Share Posted July 30, 2016 Get a faster CPU or look into doing what you want to do in DirectX. Link to comment Share on other sites More sharing options...
UEZ Posted July 30, 2016 Share Posted July 30, 2016 You can use GDI instead of GDI+ and use GUISetOnEvent: #include <GUIConstantsEx.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> AutoItSetOption("GUIOnEventMode", 1) $Width = @DesktopWidth/5 $Height = @DesktopHeight/5 $Form = GUICreate("GUI", $Width, $Height, -1, -1) $Pic= GUICtrlCreatePic("", 0, 0, $Width, $Height) GUISetState(@SW_SHOW) $hCtrl = GUICtrlGetHandle($Pic) $hGUI_DC = _WinAPI_GetDC($Form) $hDC = _WinAPI_GetDC(0) _WinAPI_SetStretchBltMode($hGUI_DC, $STRETCH_HALFTONE) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") While 1 $Timer = TimerInit() _WinAPI_StretchBlt($hGUI_DC, 0, 0, $Width, $Height, $hDC, 0, 0, @DesktopWidth, @DesktopHeight, $SRCCOPY) ToolTip(TimerDiff($Timer)) WEnd Func _Exit() _WinAPI_ReleaseDC($Form, $hGUI_DC) _WinAPI_ReleaseDC(0, $hDC) GUIDelete() Exit EndFunc Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Loken Posted July 31, 2016 Author Share Posted July 31, 2016 Thanks UEZ, code works like a charm but in 60ms. There is no way to decrease this time 10-20 ms? My CPU is intel i7 M620 2.66 Ghz. I think i dont need change my cpu. Link to comment Share on other sites More sharing options...
AndyG Posted July 31, 2016 Share Posted July 31, 2016 (edited) 13 hours ago, Loken said: Hello forum, I'm using a script to draw images on gui. Images? Or a Screenshot? I ask, because drawing a processed (minimized via _WinAPI_StretchBlt() ) image takes a lot more time than drawing an image with native size! expandcollapse popup#include <GUIConstantsEx.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> AutoItSetOption("GUIOnEventMode", 1) $Width = @DesktopWidth / 5 $Height = @DesktopHeight / 5 $Form = GUICreate("GUI", $Width, $Height, -1, -1) $Pic = GUICtrlCreatePic("", 0, 0, $Width, $Height) GUISetState(@SW_SHOW) $hCtrl = GUICtrlGetHandle($Pic) $hGUI_DC = _WinAPI_GetDC($Form) $hDC = _WinAPI_GetDC(0) _WinAPI_SetStretchBltMode($hGUI_DC, $STRETCH_HALFTONE) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Global $ptr, $hbmp $hDCbuffer = _CreateNewBmp32($Width, $Height, $ptr, $hbmp) _WinAPI_StretchBlt($hDCbuffer, 0, 0, $Width, $Height, $hDC, 0, 0, @DesktopWidth, @DesktopHeight, $SRCCOPY) While 1 $Timer = TimerInit() _WinAPI_BitBlt($hGUI_DC, 0, 0, $Width, $Height, $hDCbuffer, 0, 0, $SRCCOPY) ToolTip(TimerDiff($Timer)) WEnd Func _Exit() _WinAPI_ReleaseDC($Form, $hGUI_DC) _WinAPI_ReleaseDC(0, $hDC) GUIDelete() Exit EndFunc ;==>_Exit Func _CreateNewBmp32($iWidth, $iHeight, ByRef $ptr, ByRef $hbmp) ;erstellt leere 32-bit-Bitmap; Rückgabe $HDC und $ptr und handle auf die Bitmapdaten $hcdc = _WinAPI_CreateCompatibleDC(0) ;Desktop-Kompatiblen DeviceContext erstellen lassen $tBMI = DllStructCreate($tagBITMAPINFO) ;Struktur der Bitmapinfo erstellen und Daten eintragen DllStructSetData($tBMI, 1, DllStructGetSize($tBMI) - 4) ;Structgröße abzüglich der Daten für die Palette DllStructSetData($tBMI, 2, $iWidth) DllStructSetData($tBMI, 3, -$iHeight) ;minus =standard = bottomup DllStructSetData($tBMI, 4, 1) DllStructSetData($tBMI, 5, 32) ;32 Bit = 4 Bytes => AABBGGRR $adib = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', $DIB_RGB_COLORS, 'ptr*', 0, 'ptr', 0, 'uint', 0) $hbmp = $adib[0] ;hbitmap handle auf die Bitmap, auch per GDI+ zu verwenden $ptr = $adib[4] ;pointer auf den Anfang der Bitmapdaten, vom Assembler verwendet ;_arraydisplay($adib) _WinAPI_SelectObject($hcdc, $hbmp) ;objekt hbitmap in DC Return $hcdc ;DC der Bitmap zurückgeben EndFunc ;==>_CreateNewBmp32 Func _DeleteBitmap32($DC, $ptr, $hbmp) _WinAPI_DeleteDC($DC) _WinAPI_DeleteObject($hbmp) $ptr = 0 EndFunc ;==>_DeleteBitmap32 Edited July 31, 2016 by AndyG Link to comment Share on other sites More sharing options...
JohnOne Posted July 31, 2016 Share Posted July 31, 2016 1 hour ago, Loken said: Thanks UEZ, code works like a charm but in 60ms. There is no way to decrease this time 10-20 ms? My CPU is intel i7 M620 2.66 Ghz. I think i dont need change my cpu. UEZ script takes 20-40 ms on my scabby i5 laptop. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Loken Posted July 31, 2016 Author Share Posted July 31, 2016 AndyG's script is really fast. But drawed image's color is very bad. Link to comment Share on other sites More sharing options...
JohnOne Posted July 31, 2016 Share Posted July 31, 2016 Yes but it just draws the same image over and over AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
AndyG Posted July 31, 2016 Share Posted July 31, 2016 (edited) 21 minutes ago, Loken said: But drawed image's color is very bad. Did you changed the parameters of the StretchBlt() ? Did you ever written an image size reducing function before? Did you got better results? Can you show them? Edited July 31, 2016 by AndyG Link to comment Share on other sites More sharing options...
JohnOne Posted July 31, 2016 Share Posted July 31, 2016 8 minutes ago, JohnOne said: Yes but it just draws the same image over and over Fix it like this ;_WinAPI_StretchBlt($hDCbuffer, 0, 0, $Width, $Height, $hDC, 0, 0, @DesktopWidth, @DesktopHeight, $SRCCOPY) While 1 $Timer = TimerInit() _WinAPI_StretchBlt($hDCbuffer, 0, 0, $Width, $Height, $hDC, 0, 0, @DesktopWidth, @DesktopHeight, $SRCCOPY) _WinAPI_BitBlt($hGUI_DC, 0, 0, $Width, $Height, $hDCbuffer, 0, 0, $SRCCOPY) ToolTip(TimerDiff($Timer)) WEnd Now how fast? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Loken Posted July 31, 2016 Author Share Posted July 31, 2016 Just now, JohnOne said: Fix it like this ;_WinAPI_StretchBlt($hDCbuffer, 0, 0, $Width, $Height, $hDC, 0, 0, @DesktopWidth, @DesktopHeight, $SRCCOPY) While 1 $Timer = TimerInit() _WinAPI_StretchBlt($hDCbuffer, 0, 0, $Width, $Height, $hDC, 0, 0, @DesktopWidth, @DesktopHeight, $SRCCOPY) _WinAPI_BitBlt($hGUI_DC, 0, 0, $Width, $Height, $hDCbuffer, 0, 0, $SRCCOPY) ToolTip(TimerDiff($Timer)) WEnd Now how fast? Now fast but color is very bad. Link to comment Share on other sites More sharing options...
UEZ Posted July 31, 2016 Share Posted July 31, 2016 @Loken: change the _CreateNewBmp32 function to this (added one line) to increase quality. Func _CreateNewBmp32($iWidth, $iHeight, ByRef $ptr, ByRef $hbmp) ;erstellt leere 32-bit-Bitmap; Rückgabe $HDC und $ptr und handle auf die Bitmapdaten $hcdc = _WinAPI_CreateCompatibleDC(0) ;Desktop-Kompatiblen DeviceContext erstellen lassen _WinAPI_SetStretchBltMode($hcdc, $STRETCH_HALFTONE) $tBMI = DllStructCreate($tagBITMAPINFO) ;Struktur der Bitmapinfo erstellen und Daten eintragen DllStructSetData($tBMI, 1, DllStructGetSize($tBMI) - 4) ;Structgröße abzüglich der Daten für die Palette DllStructSetData($tBMI, 2, $iWidth) DllStructSetData($tBMI, 3, -$iHeight) ;minus =standard = bottomup DllStructSetData($tBMI, 4, 1) DllStructSetData($tBMI, 5, 32) ;32 Bit = 4 Bytes => AABBGGRR $adib = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', $DIB_RGB_COLORS, 'ptr*', 0, 'ptr', 0, 'uint', 0) $hbmp = $adib[0] ;hbitmap handle auf die Bitmap, auch per GDI+ zu verwenden $ptr = $adib[4] ;pointer auf den Anfang der Bitmapdaten, vom Assembler verwendet ;_arraydisplay($adib) _WinAPI_SelectObject($hcdc, $hbmp) ;objekt hbitmap in DC Return $hcdc ;DC der Bitmap zurückgeben EndFunc ;==>_CreateNewBmp32 Do you want to display one image to the GUI or the entired desktop permanently? Loken 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Loken Posted July 31, 2016 Author Share Posted July 31, 2016 I want to show image in a loop. Not one time. And your quality code is very nice Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now