ithelast Posted June 20, 2012 Share Posted June 20, 2012 I am looking for a way to convert the relative coordinates on a 1920 x 1080 resolution to the equivalent coordinates in 800 x 600. This formula works to do it manually however its extremely inefficient if you are looking to convert a large number of cordiantes: (new_x = old_x * (new_screen_width / old_screen_width)), (new_y = old_y * (new_screen_width / old_screen_width)). Is there a good Autoit script to do this? Or maybe with another utility? Link to comment Share on other sites More sharing options...
water Posted June 20, 2012 Share Posted June 20, 2012 (edited) Welcome to AutoIt and the forum! You have the formula, that's half the AutoIt script. Screen width and height can be retrieved using the macros @DesktopHeight and @DesktopWidth. Edited June 20, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
ithelast Posted June 20, 2012 Author Share Posted June 20, 2012 Wow that was a fast reply! Thank you for the warm welcome... Much appreciated. Would something like this work? ;convert coords (x,y) from (a,b ) screen resolution to (c,d) screen resolution Func_ConvertCoords( $x, $y, $a, $b, $c = @DesktopWidth, $d = @DesktopHeight ) Local $ret[2] = [( $c * $x ) / $a, ( $d * $y ) / $b] Return $ret EndFunc How to I get Autoit to allow a way to input these cords and then provide an output for it? Please forgive the ignorance as I a complete AutoIt newbie. Link to comment Share on other sites More sharing options...
water Posted June 20, 2012 Share Posted June 20, 2012 (edited) I created this test script and it returns some good looking results (didn't check the math). #include <array.au3> Global $aResult = _ConvertCoords(100, 200, 800, 600) _Arraydisplay($aResult) Func _ConvertCoords($x, $y, $a, $b, $c = @DesktopWidth, $d = @DesktopHeight) Local $ret[2] = [($c * $x) / $a, ($d * $y) / $b] Return $ret EndFunc ;==>_ConvertCoords To answer your second questions it would help to know why you want to process these coords? Where are the coords stored now (a file, a database ...)? What application do you want to feed the new coords to? Edited June 20, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
ithelast Posted June 29, 2012 Author Share Posted June 29, 2012 (edited) I simply want to make a utility (Pixel Conversion Calculator?) that will allow you to convert pixel coordinates between resolutions. It does not seem anything like this exists. You totally put me in the right direction: Thank you! Here is the code I have been using: #include <array.au3> Global $aResult = _ConvertCoords(1920, 1080, 800, 600) _Arraydisplay($aResult) Func _ConvertCoords($a, $b, $c, $d, $x = 960, $y = 540) Local $ret[2] = [($x * ($c / $a)), ($y * ($d / $)] Return $ret EndFunc ;==>_ConvertCoords This converts the pixel coordinates given in $x and $y. From resolution a, b (in this case 1920 by 1080) to the desired resolution pixel coordinates (in this case 800 x 600). Example: [($x * ($c / $a)), ($y * ($d / $)] is 960 (1920/800), 540(1080/600) = 960(.4166), 540(.4166) = 400, 300 1. Ideally the array would allow you to input the values for $x and $y so it could be a stand alone utility. 2. Even better If you could also change the values for $a,$b,$c,$d then you would also be able to modify the resolution on the fly as well. Edited June 29, 2012 by ithelast 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