annelinn Posted May 16, 2009 Share Posted May 16, 2009 (edited) Can anyone suggest an obviously wrong line of code? expandcollapse popupGlobal $Image_handle ; Handle of the captured bitmap image Global $Xpos, $Ypos, $Width, $Height; The area in which to draw a rectangle Func CaptureImage() ; Capture the image $Image_handle = _ScreenCapture_Capture("", $region_topx_absolute, $region_topy_absolute, $region_bottomx_absolute, $region_bottomy_absolute, False) ; Save the image as a file _ScreenCapture_SaveImage($Image_currentfile, $Image_handle) ; Display it on screen RefreshImage() EndFunc Func RefreshImage() ; Destroy and recreate the image control GUICtrlDelete($Mwin_imagebox) $Mwin_imagebox = GUICtrlCreatePic("", 10, 10, 0, 0) ; Refresh the image from the bitmap file GUICtrlSetPos($Mwin_imagebox, $Mwin_imagebox_xposition, $Mwin_imagebox_yposition) GUICtrlSetImage($Mwin_imagebox, $Image_currentfile) ; Draw a rectangle in a certain position RefreshRectangle() EndFunc Func RefreshRectangle() Local $bitmap, $graphics ; Initialize GDI+ library _GDIPlus_Startup () ; Draw the rectangle $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($Image_handle) $graphics = _GDIPlus_ImageGetGraphicsContext($bitmap) _GDIPlus_GraphicsDrawRect($graphics, $Xpos, $Ypos, $Width, $Height) ; Shut down GDI+ library _GDIPlus_ShutDown () EndFuncJScrape_3.au3 Edited May 16, 2009 by annelinn Link to comment Share on other sites More sharing options...
martin Posted May 16, 2009 Share Posted May 16, 2009 (edited) Can anyone suggest an obviously wrong line of code? expandcollapse popupGlobal $Image_handle ; Handle of the captured bitmap image Global $Xpos, $Ypos, $Width, $Height; The area in which to draw a rectangle Func CaptureImage() ; Capture the image $Image_handle = _ScreenCapture_Capture("", $region_topx_absolute, $region_topy_absolute, $region_bottomx_absolute, $region_bottomy_absolute, False) ; Save the image as a file _ScreenCapture_SaveImage($Image_currentfile, $Image_handle) ; Display it on screen RefreshImage() EndFunc Func RefreshImage() ; Destroy and recreate the image control GUICtrlDelete($Mwin_imagebox) $Mwin_imagebox = GUICtrlCreatePic("", 10, 10, 0, 0) ; Refresh the image from the bitmap file GUICtrlSetPos($Mwin_imagebox, $Mwin_imagebox_xposition, $Mwin_imagebox_yposition) GUICtrlSetImage($Mwin_imagebox, $Image_currentfile) ; Draw a rectangle in a certain position RefreshRectangle() EndFunc Func RefreshRectangle() Local $bitmap, $graphics ; Initialize GDI+ library _GDIPlus_Startup () ; Draw the rectangle $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($Image_handle) $graphics = _GDIPlus_ImageGetGraphicsContext($bitmap) _GDIPlus_GraphicsDrawRect($graphics, $Xpos, $Ypos, $Width, $Height) ; Shut down GDI+ library _GDIPlus_ShutDown () EndFunc It would be much better if you posted some code which we could actually run. You are drawing on the bitmap which is just an area in memory so you won't see anything. You need to replace these 2 lines $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($Image_handle) $graphics = _GDIPlus_ImageGetGraphicsContext($bitmap) with $graphics = _GDIPlus_GraphicsCreateFromHWND($Gui) where $Gui is the gui you are drawing in. Or if you are drawing in a control then instead of $Gui use ControlGetHandle($Gui,"",$ControlID) Edited May 16, 2009 by martin 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...
annelinn Posted May 16, 2009 Author Share Posted May 16, 2009 Thanks! I assume you mean this: $graphics = _GDIPlus_GraphicsCreateFromHWND(ControlGetHandle($Mwin_handle, "" ,$Mwin_imagebox)) _GDIPlus_GraphicsDrawRect($graphics, $Xpos, $Ypos, $Width, $Height) ...where $Mwin_handle is the handle of the GUI window, and $Mwin_imagebox is the control ID of the picture control. I still don't see the rectangle! It would be much better if you posted some code which we could actually run.Did you miss the attachment at the bottom of the original post? Here it is again:JScrape_3.au3 Link to comment Share on other sites More sharing options...
oMBRa Posted May 16, 2009 Share Posted May 16, 2009 check if ControlGetHandle($Mwin_handle, "" ,$Mwin_imagebox) returns a valid handle or an error Link to comment Share on other sites More sharing options...
martin Posted May 16, 2009 Share Posted May 16, 2009 (edited) Thanks! I assume you mean this: $graphics = _GDIPlus_GraphicsCreateFromHWND(ControlGetHandle($Mwin_handle, "" ,$Mwin_imagebox)) _GDIPlus_GraphicsDrawRect($graphics, $Xpos, $Ypos, $Width, $Height) ...where $Mwin_handle is the handle of the GUI window, and $Mwin_imagebox is the control ID of the picture control. I still don't see the rectangle!Yes, tghat's what I meant. Did you miss the attachment at the bottom of the original post? Here it is again: I suppose I did. Actually, it was worse than that. I saw it and assumed it was a repeat of what you posted. Apologies; I will pay for my error by looking at you code now Edited May 16, 2009 by martin 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...
annelinn Posted May 16, 2009 Author Share Posted May 16, 2009 (edited) check if ControlGetHandle($Mwin_handle, "" ,$Mwin_imagebox) returns a valid handle or an errorI have checked, both are valid. (I think there's a MsgBox() call commented out somewhere in the code.)NB Latest version with better comments below. The rectangle is supposed to appear after the "scrape text" operation is completeJScrape_v0_4.au3JScrape_UserGuide.txt Edited May 16, 2009 by annelinn Link to comment Share on other sites More sharing options...
martin Posted May 16, 2009 Share Posted May 16, 2009 (edited) I have checked, both are valid. (I think there's a MsgBox() call commented out somewhere in the code.)NB Latest version with better comments below. The rectangle is supposed to appear after the "scrape text" operation is completeI had a look again and didn't get very far. Trying to draw on a pic doesn't work I'm afraid, though drawing on a graphic does. I tried using a label and it works in a way but perhaps the styles need different. Using the style $SS_BLACKFRAME gives a rectangle and a label has the advantage that you can resize and move it and it is redrawn automatically. EDIT: Attachment removed because I remembered how to draw on a Pic, see next post.JScrape_v0_4.au3 Edited May 17, 2009 by martin 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...
martin Posted May 17, 2009 Share Posted May 17, 2009 This is how you can draw on the image. #Region ***********draw a red rectangle over the image $hPic = GUICtrlGetHandle($Mwin_imagebox) _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hPic) $hPen = _GDIPlus_PenCreate(0xffff0000, 3);red, 3pixels wide _GDIPlus_GraphicsDrawRect($hGraphic, 20, 20, 40, 40, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() #EndRegion ***********draw a red rectangle over the image But it has to be redrawn every time the windiow needs to be repainted so labels might be easier in the end. 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...
annelinn Posted May 17, 2009 Author Share Posted May 17, 2009 (edited) But it has to be redrawn every time the windiow needs to be repainted so labels might be easier in the end.Actually, I love the previous label solution, and the largish frame is just what I wanted. Thanks, Martin, many times over.JScrape_v1_0.zip Edited May 17, 2009 by annelinn Link to comment Share on other sites More sharing options...
martin Posted May 17, 2009 Share Posted May 17, 2009 (edited) Actually, I love the previous label solution, and the largish frame is just what I wanted. Thanks, Martin, many times over.NP, there's no acounting for people's taste If you want to draw over the pic and make it part of the pic so that it doesn't need to be repainted then this example by Malkey will be helpful.mgrefMalkeyPic1 Edited May 17, 2009 by martin 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 May 17, 2009 Share Posted May 17, 2009 Have a look on the GDI+ examples -> http://www.autoitscript.com/forum/index.php?showtopic=87200 and check #07 Visualization: Analog MeterI used 2 PNG images and drew a needle on it. You can save it easily because it is double buffered (check the posts).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...
martin Posted May 18, 2009 Share Posted May 18, 2009 Have a look on the GDI+ examples -> http://www.autoitscript.com/forum/index.php?showtopic=87200 and check #07 Visualization: Analog MeterI used 2 PNG images and drew a needle on it. You can save it easily because it is double buffered (check the posts).UEZYes, I know that one and I saved it in my examples a long time ago. It's excellent UEZ. 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...
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