MrChiliCheese Posted June 21, 2009 Share Posted June 21, 2009 Hi, i have a problem with the following code. After about 30 secons i get an error message: (For this command enough memory is not available.) I think it is, because the _Shot function is called in a loop and after a while there isn't enough memory. Or is there a mistake in my code calling GDI+? #include <ScreenCapture.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("MonView", 490, 280) GUISetState() $timer = TimerInit() Do If TimerDiff($timer) > 400 Then $timer = TimerInit() _Shot() EndIf Sleep (10) Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Func _Shot() _GDIPlus_Startup () $sCap = _GDIPlus_BitmapCreateFromHBITMAP(_ScreenCapture_Capture("",1280,0,3200,1080)) $sCapX = _GDIPlus_ImageGetWidth($sCap) $sCapY = _GDIPlus_ImageGetHeight($sCap) $sGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) _GDIPlus_GraphicsDrawImageRectRect ($sGraphic, $sCap, 0, 0, $sCapX, $sCapY, 5, 5, 0.25*$sCapX, 0.25*$sCapY) _GDIPlus_GraphicsDispose ($sGraphic) _GDIPlus_ImageDispose ($sCap) _GDIPlus_Shutdown () EndFunc Thanks a lot Link to comment Share on other sites More sharing options...
monoceres Posted June 21, 2009 Share Posted June 21, 2009 Hi! In this line: $sCap = _GDIPlus_BitmapCreateFromHBITMAP(_ScreenCapture_Capture("",1280,0,3200,1080)) .. there is a memory leak. the hbitmap you recieve from _ScreenCapture_Capture() must be cleaned up with _WinAPI_DeleteObject. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
martin Posted June 21, 2009 Share Posted June 21, 2009 Hi, i have a problem with the following code. After about 30 secons i get an error message: (For this command enough memory is not available.) I think it is, because the _Shot function is called in a loop and after a while there isn't enough memory. Or is there a mistake in my code calling GDI+? #include <ScreenCapture.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("MonView", 490, 280) GUISetState() $timer = TimerInit() Do If TimerDiff($timer) > 400 Then $timer = TimerInit() _Shot() EndIf Sleep (10) Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Func _Shot() _GDIPlus_Startup () $sCap = _GDIPlus_BitmapCreateFromHBITMAP(_ScreenCapture_Capture("",1280,0,3200,1080)) $sCapX = _GDIPlus_ImageGetWidth($sCap) $sCapY = _GDIPlus_ImageGetHeight($sCap) $sGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) _GDIPlus_GraphicsDrawImageRectRect ($sGraphic, $sCap, 0, 0, $sCapX, $sCapY, 5, 5, 0.25*$sCapX, 0.25*$sCapY) _GDIPlus_GraphicsDispose ($sGraphic) _GDIPlus_ImageDispose ($sCap) _GDIPlus_Shutdown () EndFunc Thanks a lot You need to read the help for _ScreenCapture_Capture #include <ScreenCapture.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("MonView", 490, 280) GUISetState() $timer = TimerInit() Do If TimerDiff($timer) > 400 Then $timer = TimerInit() _Shot() EndIf Sleep(10) Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Func _Shot() _GDIPlus_Startup() $hBm = _ScreenCapture_Capture("", 1280, 0, 3200, 1080) $sCap = _GDIPlus_BitmapCreateFromHBITMAP($hBm) _WinAPI_DeleteObject($hBm) $sCapX = _GDIPlus_ImageGetWidth($sCap) $sCapY = _GDIPlus_ImageGetHeight($sCap) $sGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawImageRectRect($sGraphic, $sCap, 0, 0, $sCapX, $sCapY, 5, 5, 0.25 * $sCapX, 0.25 * $sCapY) _GDIPlus_GraphicsDispose($sGraphic) _GDIPlus_ImageDispose($sCap) _GDIPlus_Shutdown() EndFunc ;==>_Shot Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
UEZ Posted June 22, 2009 Share Posted June 22, 2009 (edited) I just want to add that you don't need to initialize GDI+ in every loop: #include <ScreenCapture.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> #include <GDIplus.au3> _GDIPlus_Startup() $hGUI = GUICreate("MonView", 490, 280) GUISetState() $timer = TimerInit() Do If TimerDiff($timer) > 400 Then $timer = TimerInit() _Shot() EndIf Sleep(10) Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() _GDIPlus_Shutdown() Func _Shot() $hBm = _ScreenCapture_Capture("", 1280, 0, 3200, 1080) $sCap = _GDIPlus_BitmapCreateFromHBITMAP($hBm) _WinAPI_DeleteObject($hBm) $sCapX = _GDIPlus_ImageGetWidth($sCap) $sCapY = _GDIPlus_ImageGetHeight($sCap) $sGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawImageRectRect($sGraphic, $sCap, 0, 0, $sCapX, $sCapY, 5, 5, 0.25 * $sCapX, 0.25 * $sCapY) _GDIPlus_GraphicsDispose($sGraphic) _GDIPlus_ImageDispose($sCap) EndFunc ;==>_Shot UEZ Edited June 22, 2009 by UEZ 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...
MrChiliCheese Posted June 26, 2009 Author Share Posted June 26, 2009 Oh god, that simple... i think i need a RTFM sticker on my monitor thanks @ UEZ Link to comment Share on other sites More sharing options...
rover Posted June 29, 2009 Share Posted June 29, 2009 you also have a GDI objects leak from a minor bug with_ScreenCapture_Capture() if you don't need the cursor, add False to this line: $hBm = _ScreenCapture_Capture("", 1280, 0, 3200, 1080, False)[code=auto:0] or download the attachment _ScreenCapture_Capture() in the Trac ticket submitted to Trac: _ScreenCapture_Capture(): GDI object leak with cursor capture #1040 I see fascists... Link to comment Share on other sites More sharing options...
MrChiliCheese Posted June 29, 2009 Author Share Posted June 29, 2009 good to know, thanks for the info 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