Jump to content

GUICtrlCreatePic Bitmap Resizing


EOL
 Share

Recommended Posts

I'm trying to layer a company logo bitmap over the upper left corner of a graphic control. Because different divisions in the company have different logos, the idea is to specify "0" for height and width within the GUICtrlCreatePic function to account for the slight variation in logo sizes post compile. This approach works perfectly until the GUI is minimized and subsequently restored from the taskbar. The logo image resizes within the GUI and appears to center off of the graphic control. Is there something wrong with my code that would cause this behavior?

As a work around I've loaded the GDIPlus UDF and populated variables with the ImageGetWidth/ ImageGetHeight functions to define the image file dimensions. This extra code resolves the issue but I'd prefer to not add it if it's not needed.

#include <GUIConstantsEx.au3>

;-----------------------------------------------------------------------------------------------------------
;    Int Main()
;-----------------------------------------------------------------------------------------------------------

_ShowGUI()

;-----------------------------------------------------------------------------------------------------------
;    Show GUI
;-----------------------------------------------------------------------------------------------------------

Func _ShowGUI()

    GUICreate("GUICtrlCreatePic Test", 636, 497, -1, -1)
    GUICtrlCreateGraphic(16, 16, 605, 400)
    ;GUICtrlCreateLabel("", 16, 16, 605, 400)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlCreatePic(@ScriptDir & "\Default_Logo.bmp", 16, 16, 0, 0)
    $hButton = GUICtrlCreateButton("&Close", 512, 438, 97, 25)

    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $hButton Or $msg = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect
    WEnd
    GUIDelete()
EndFunc

I've also tested:

With several images from different sources (Sample attached)

Replacing GUICtrlCreateGraphic function with GUICtrlCreateLabel (Same result)

Using GUICtrlCreatePic NOT layered over another control (Did NOT resize bitmap)

On Windows 7 64bit, Windows XP SP3 (32 & 64bit), Server 2003 32bit and 2008 64bit

Compiled and within SciTE 1.79 (Both AutoIt 3.3.6.1)

Link to comment
Share on other sites

this should do it:

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
Global $Width3, $Height3, $Width2, $Height2
;-----------------------------------------------------------------------------------------------------------
;    Int Main()
;-----------------------------------------------------------------------------------------------------------

_ShowGUI()

;-----------------------------------------------------------------------------------------------------------
;    Show GUI
;-----------------------------------------------------------------------------------------------------------
func _picdim ($rp, $rp1, $rp2);$picture, $maxwidth, $maxheight
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile($rp)
    $Width = _GDIPlus_ImageGetWidth($hImage)
    $Height = _GDIPlus_ImageGetHeight($hImage)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    $i = $rp1
    $xa = $Width / $rp1
    while $Height / $xa > $rp2
        $i -= 1
        $xa = $Width / $i
    wend
    $Width2 = $Width
    $Height2 = $Height
    if $Width > $rp1 or $Height > $rp2 then
        $Width2 = int($Width / $xa)
        $Height2 = int($Height / $xa)
    endif
    $Width3 = 0
    $Height3 = 0
    if int(($rp1 - $Width2) / 2) > 1 then $Width3 = int(($rp1 - $Width2) / 2)
    if int(($rp2 - $Height2) / 2) > 1 then $Height3 = int(($rp2 - $Height2) / 2)
endfunc
;width2 = new calculated image width
;height2 = new calculated image height
;you need width3 and height3 only if you want to display logo in center
;width3 = calculated space from the right side till picture begin
;height3 = calculated space from the top till picture begin
Func _ShowGUI()

    GUICreate("GUICtrlCreatePic Test", 636, 497, -1, -1)
    GUICtrlCreateGraphic(16, 16, 605, 400)
    ;GUICtrlCreateLabel("", 16, 16, 605, 400)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    _picdim (@ScriptDir & "\Default_Logo.bmp", 605, 400)
    GUICtrlCreatePic(@ScriptDir & "\Default_Logo.bmp", $Width3, $Height3, $Width2, $Height2)
    $hButton = GUICtrlCreateButton("&Close", 512, 438, 97, 25)

    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $hButton Or $msg = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect
    WEnd
    GUIDelete()
EndFunc
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...