Valnurat Posted August 6, 2019 Posted August 6, 2019 I have this code and I want to control the size of the picture that is being showing on the GUI not matter how big the source of the picture is. To draw the picture you just add the x and y position, but I would like a end position too. expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <AD.au3> Global $sUsername = 'shortname' Example() Func Example() _GDIPlus_Startup() ;initialize GDI+ Local Const $iWidth = 300, $iHeight = 300, $iBgColor = 0xFFE8FF ;$iBgColor format RRGGBB Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI GUISetBkColor($iBgColor, $hGUI) ;set GUI background color GUISetState(@SW_SHOW) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle Local $hBitmap = _GDIPlus_BitmapCreateFromMemory(_ADO_USERIMAGE($sUsername)) ;load binary saved GIF image and convert it to GDI+ bitmap format if Not @error Then Local $iW = _GDIPlus_ImageGetWidth($hBitmap), $iH = _GDIPlus_ImageGetHeight($hBitmap) MsgBox(0, $iW, $iH) _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 15, 20) ;display image in GUI EndIf Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ;cleanup GDI+ resources _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGUI) EndFunc ;==>Example Func _ADO_USERIMAGE($sUsename) _AD_Open() Local $oADO_USERIMAGE = _AD_GetObjectAttribute($sUseName, 'thumbnailPhoto') If @error Then Exit _AD_Close() Return $oADO_USERIMAGE EndFunc Yours sincerely Kenneth.
Nine Posted August 6, 2019 Posted August 6, 2019 Very easy, here an example : expandcollapse popup#include <GUIConstants.au3> #include <GDIPlus.au3> #include <SendMessage.au3> #include <ScreenCapture.au3> #include <Constants.au3> Local $Form = GUICreate("Test Resize", 500, 500) Local $Pic = GUICtrlCreatePic("", 100, 100, 300, 300) GUISetState(@SW_SHOW) _GDIPlus_Startup() $hBitmap2 = _ScreenCapture_Capture("", 100, 100, 300, 300, False) ; 200 x 200 $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2) $hImage = _GDIPlus_ImageResize($hImage2, 300, 300) ; resize to 300 x 300 $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _SetBitmapToCtrl($Pic, $hBitmap) ;Clean up and shutdown GDIPlus. _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hImage2) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hBitmap2) _GDIPlus_Shutdown() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($Form) ; ============================================ Func _SetBitmapToCtrl($CtrlId, $hBitmap) Local Const $SS_IMAGE_BITMAP = 0 Local $hWnd = GUICtrlGetHandle($CtrlId) If $hWnd = 0 Then Return SetError(1, 0, 0) _SendMessage($hWnd, $STM_SETIMAGE, $SS_IMAGE_BITMAP, $hBitmap) If @error Then Return SetError(4, 0, 0) Return 1 EndFunc ;==>_SetBitmapToCtrl “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Valnurat Posted August 6, 2019 Author Posted August 6, 2019 (edited) I get an undefined function error on : _SetBitmapToCtrl(): undefined function. EDIT: Never mind. I should have copied all code before trying. Doh. Edited August 6, 2019 by Valnurat Yours sincerely Kenneth.
Valnurat Posted August 7, 2019 Author Posted August 7, 2019 If I use your example in my code I get: warning: $STM_SETIMAGE: possibly used before declaration. and error: $STM_SETIMAGE: undeclared global variable But in your example I don't get these. Do you know why? Yours sincerely Kenneth.
Nine Posted August 7, 2019 Posted August 7, 2019 $STM_SETIMAGE is a constant declared in StaticConstants.au3 which is included in Constants.au3. Include either one of those in your script... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
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