Jump to content

How do I control the size of the picture


Valnurat
 Share

Recommended Posts

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.

#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.

Link to comment
Share on other sites

Very easy, here an example :

#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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...