4 posts in this topic
Dear AutoIT Community.
I am currently working on a program that will display lots of images in a scroll down GUI.
I create the GUI based on the number of images, which works fine.
But all images I place using GuiCtrlCreatePic above a threshold of around 32000 pixels (cant say exactly) are placed at negative locations and finally will reach 0 again
and will then populate on top of the images placed there before.
For $i = 1 To $Images ; Get picture dimensions $hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $Images[$i]) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) ; Resize & place images in GUI $Pic[$i] = GUICtrlCreatePic($ImgRep & $Images[$i], $Spacer, Round($yPos, 0), $MaxImgWidth, $MaxImgWidth * ($iY / $iX)) $yPos = $yPos + $MaxImgWidth * ($iY / $iX) + $Spacer $log = $log & "|" & $yPos $currentlut = $Images Next I have found a limit at 32767 pixels for some GUI elements when googling around.
Can someone tell me how to circumvent that?
This script generates Barnsleys Fractal Fern using script only.
; version 2017-10-03 ; Barnsley Fractal Fern ; by larnil #include <GUIConstants.au3> Dim $x, $y, $xn, $yn, $n, $r, $dc $WinSize = 800 ; window size ;Create graphics windows AutoItSetOption("GUIOnEventMode", 1) $GUI = GUICreate("Barnsley Fractal Fern", $WinSize, $WinSize, -1, -1) $Graphic = GuiCtrlCreateGraphic(0, 0, $WinSize, $WinSize) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0x00ff00) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE,"Bye") ;Main $start = TimerInit() _Fern(800) ; hight of fern - can be larger than window MsgBox(0,"Time taken:",Round(TimerDiff($start)/1000,3) &" seconds") While 1 Sleep(100) WEnd Func Bye() Exit EndFunc Func _Fern($height) $f = $height/10.6 ; scale factor. Complete fern is within 0 <= y <= 9.9983 (with no scale) $offset_x = $height/2 - $height/40 ; Side adjustment. Fern is within −2.1820 < x < 2.6558 (with no scale) For $n = 1 To $height*200 ; Number of iterations $r = Random(0, 99, 1) Select Case $r < 85 ; 0-84 = 85% of the time $xn = 0.85 * $x + 0.04 * $y $yn = -0.04 * $x + 0.85 * $y + 1.6 Case $r > 84 AND $r < 92 ; 85-91 = 7% of the time $xn = 0.2 * $x - 0.26 * $y $yn = 0.23 * $x + 0.22 * $y + 1.6 Case $r > 91 AND $r < 99 ; 92-98 = 7% of the time $xn = -0.15 * $x + 0.28 * $y $yn = 0.26 * $x + 0.24 * $y + 0.44 Case Else ; 99-99 = 1% of the time $xn = 0 $yn = 0.16 * $y EndSelect $x = $xn $y = $yn GUICtrlSetGraphic($Graphic, $GUI_GR_PIXEL, $offset_x + $x * $f, $height - $y * $f) Next GUICtrlSetGraphic($Graphic, $GUI_GR_REFRESH) EndFunc ;==> Fern
Here is another example where I have used GDI (my very first attempt at using GDI by the way). This script can generate much larger Ferns and save them to file (png). I have used this script to generate a 20000 x 20000 pixel @ 600 dpi image. Looks really good printed out in full size.
#include <GDIPlus.au3> #include <GUIConstantsEx.au3> ; Param Local Const $iPxColor = 0xFF00FF00 ; Pixel color for fractal Alpha/R/G/B Local Const $iBgColor = 0xFFFFFFFF ; Background color for image Alpha/R/G/B Local Const $iSize = 1000 ; Hight of fern in pixels - image will have this hight and width too Local Const $iIter = $iSize*400 ; Number of iterations - $iSize * 200 is a good starting point ; Call function ;$start = TimerInit() _Fern($iSize,$iIter) ;MsgBox(0,"Time taken:",Round(TimerDiff($start)/1000,3) &" seconds") ; Function for generating Barnsley Fractal Fern Func _Fern($Size,$Iter) _GDIPlus_Startup() ; initialize GDI+ Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($Size, $Size) ; create an empty bitmap Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; get the graphics context of the image _GDIPlus_GraphicsClear($hBmpCtxt, $iBgColor) ; Set the background color for empty bitmap ; Here the magic happens $x=0 ; init $y=0 ; init $f = $Size/10.6 ; scale factor. Complete fern is within 0 <= y <= 9.9983 (with no scale) $offset_x = $Size/2 - $Size/40 ; Side adjustment. Fern is within −2.1820 < x < 2.6558 (with no scale) For $n = 1 To $Iter ; Number of iterations $r = Random(0, 99, 1) Select Case $r < 85 ; 0-84 = 85% of the time $xn = 0.85 * $x + 0.04 * $y $yn = -0.04 * $x + 0.85 * $y + 1.6 Case $r > 84 AND $r < 92 ; 85-91 = 7% of the time $xn = 0.2 * $x - 0.26 * $y $yn = 0.23 * $x + 0.22 * $y + 1.6 Case $r > 91 AND $r < 99 ; 92-98 = 7% of the time $xn = -0.15 * $x + 0.28 * $y $yn = 0.26 * $x + 0.24 * $y + 0.44 Case Else ; 99-99 = 1% of the time $xn = 0 $yn = 0.16 * $y EndSelect $x = $xn $y = $yn _GDIPlus_BitmapSetPixel($hBitmap, $offset_x + $x * $f, $Size - $y * $f, $iPxColor) ; Change pixel color for calculated X,Y Next ; ==> End of magic $File = "\Fractal_Fern_"&StringRight(Hex($iPxColor),6)&"-"&StringRight(Hex($iBgColor),6)&"-"&$iSize&".png" _GDIPlus_ImageSaveToFile($hBitmap, @MyDocumentsDir & $File) ;save bitmap to disk ShellExecute(@MyDocumentsDir & $File); Show it to the world in your default image viewer ; Cleanup GDI+ resources _GDIPlus_GraphicsDispose($hBmpCtxt) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndFunc ;==> _Fern
If possible please add or edit the comments to explain how this works.
;includes functions from other things
Global $win_title ;name of the window
Global $area_x ;
Global $area_y ;
Global $area_w ;
Global $area_h ;
Global $cursor ;
Global $rect_file ;
Global $hbmpscreen ;
Global $i= 1043 ;moves the rect
Global $ii= 378 ;moves the rect
Global $x=1044 ;inner rect offset
Global $y=501 ;inner rect offset
Global $hbmprect ;image inside rect
Global $hscreen ;image whole screen
;display hotkeys on screen
ToolTip("Press F1 to scan | Press ESC to Exit",0,0)
;infinite loop to keep prog running
;~ reads your screen area:
;~ converts screen captured into bmp
;~ . Loads converted bmp to be read
;~ compares the bmp of your scanned screen to the actual screen that is being displayed
$hscreen = _ScreenCapture_CaptureWnd("", WinGetHandle($win_title), $area_x, $area_y, $area_x + $area_w, $area_y + $area_h, $cursor)
;converts screen into bmp
;loads converted screen
;compares savedBMP to current screen
;If( below code ) = ( below code ) Then
If _GDIPlus_BitmapGetPixel($hbmpscreen, ($i + $x) - $area_x, ($ii + $y) - $area_y) = _GDIPlus_BitmapGetPixel($hbmprect, $x, $y) Then
;display message box titled found with a message of found
;if above is not correct then
Hi, i searched some topics but cannot found a simple way to do that:
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 615, 438, 192, 124) GUISetState(@SW_SHOW) ; I tried this but user reported that it work in 2006, not seems work actually $filemenu = GUICtrlCreateMenu ("&File") $fileitem = GUICtrlCreateMenuitem ("Open",$filemenu) GuiCtrlSetImage($fileitem, "shell32.dll", 4) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Also tried:
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 615, 438, 192, 124) GUISetState(@SW_SHOW) $filemenu = TrayCreateMenu("&File") $fileitem = TrayCreateItem("Open",$filemenu) ;GuiCtrlSetImage($fileitem, "shell32.dll", 4) ;GuiCtrlSetImage(TrayItemGetHandle($fileitem), "shell32.dll", 4) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Well.. thanks in advance!
Ok. I found this working example from Yashied. If i cannot find a simple then i will go with it
#Include <GUIConstantsEx.au3> #Include <GUIMenu.au3> #Include <Constants.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Global $hMenu, $hForm, $hFile = 1000, $idNew, $idExit $hForm = GUICreate('Menu', 400, 300) $hFile = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem ($hFile, 0, ' &Favorites', $idNew) _GUICtrlMenu_InsertMenuItem ($hFile, 1, '', 0) _GUICtrlMenu_InsertMenuItem($hFile, 2, ' E&xit', $idExit) $hMenu = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hMenu, 0, '&File', 0, $hFile) _GUICtrlMenu_SetMenu($hForm, $hMenu) _GUICtrlMenu_SetItemBmp($hFile, 0, _CreateBitmapFromIcon(_WinAPI_GetSysColor($COLOR_MENU), @SystemDir & '\shell32.dll', 43, 16, 16)) _GUICtrlMenu_SetItemBmp($hFile, 2, _CreateBitmapFromIcon(_WinAPI_GetSysColor($COLOR_MENU), @SystemDir & '\shell32.dll', 27, 16, 16)) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _CreateBitmapFromIcon($iBackground, $sIcon, $iIndex, $iWidth, $iHeight) Local $hDC, $hBackDC, $hBackSv, $hIcon, $hBitmap $hDC = _WinAPI_GetDC(0) $hBackDC = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateSolidBitmap(0, $iBackground, $iWidth, $iHeight) $hBackSv = _WinAPI_SelectObject($hBackDC, $hBitmap) $hIcon = _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight) If Not @error Then _WinAPI_DrawIconEx($hBackDC, 0, 0, $hIcon, 0, 0, 0, 0, $DI_NORMAL) _WinAPI_DestroyIcon($hIcon) EndIf _WinAPI_SelectObject($hBackDC, $hBackSv) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteDC($hBackDC) Return $hBitmap EndFunc ;==>_CreateBitmapFromIcon Func _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight) Local $hIcon, $tIcon = DllStructCreate('hwnd'), $tID = DllStructCreate('hwnd') Local $Ret = DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0) If (@error) Or ($Ret = 0) Then Return SetError(1, 0, 0) EndIf $hIcon = DllStructGetData($tIcon, 1) If ($hIcon = Ptr(0)) Or (Not IsPtr($hIcon)) Then Return SetError(1, 0, 0) EndIf Return $hIcon EndFunc ;==>_WinAPI_PrivateExtractIcon Ok, i noticed that is a pain create submenu with _GUICtrlMenu_CreatePopup to do like in Tray, and Tray better located, then i need images/icon with Tray functions, some workaround??
I am busy with building a solution for change monitoring of VOIP call program and to be properly automated means among others need for some limited OCR functionality. Current works of others are way too much overkill for this case what makes the need to build it myself. But to do it properly I significantly have to increase my knowledge about digital graphics management.
For now I already have discovered here and there some mind blowing Autoit miracles what can be achieved with Windows own possibilities to manipulate that what is output to the monitor. And as far I can judge there are 2 options to process graphics without use of any external libraries like ImageMagick, FreeImage and so on. These are:
WinAPI GDIPlus It is for me quite obvious to have various holes in general understanding of graphics and it is once more very clear what advantages gives consistent general study in 1 or another official institutions like University. Cause there you are introduced into certain domain of knowledge in a way which usually has been perfected over long period of time. So you are not overloaded by stuff which requires a certain amount of information to be initially clear for you. For example, before starting to solve physics you first learn to read, count and so on and then move to subjects like physics.
Though in my case opportunity to study in such educational system I had only for 8 years, from my 7th to 15th year of age in the country that was falling apart now Ukraine but used to be USSR, was all what it was. After have immigrated to Netherlands possibilities to study further haven't occur. And this therefor causes often various implications when going deep in that or another field of practical knowledge acquiring for any needed physical result, like programming to perform enormous amount of tasks. In this particular case automating VOIP call program.
Anyway, right now I think the best direction to move is to concentrate on as basic as possible image management and if someone would maybe explain in general what is a pixel will definitely help. Particularly I am very curious about how to do picture manipulations in Autoit. Especially would help a lot to produce eventually following functions:
createImage($imageFileName, $width, $height, $color) readImagePixel($imageFileName, $x, $y) writeImagePixel($imageFileName, $x, $y) I do not know exactly how image is handled in computer but preferably above mentioned functions should deal with so far possible origin of graphics creation on computer. But nevertheless I definitely would love to hear any proposition for solution.
The problem with explaining screenshots:
VOIPConnect full Window Part of Window with control to monitor for changes Exact location of area where actual changes occur and have to be processed It comes down to a rectangle of approximately 51 pixel wide and 7 pixel high. In fact if I get to learn as far as to be able exactly read, write and compare 2 images consistently across different computers I could narrow down then even further the area to watch as little as a square of 2-5 pixels wide.
To finish here is last detail about particularly no need for ultra fast solution at all. This because it is needed only once when it is first run on a new computer and to have to wait few minutes while it is being set instead of just a few seconds make no sence.
This is it and what I too think to do beside this very particular case is to purify out beautiful generic Autoit functions for core image manipulation by using WinAPI or/and GDIPlus.