Jump to content

Attempting to scroll large PNG

Recommended Posts


I'm afraid I've been looking at this too long.  I'm certain something is missing, but I can't see what.

My mission is to display a large PNG in a window with scroll bars.  When the PNG would not display, I backed down to displaying a JPG as a picture.  It also fails to show.

Here's what I have ... simplified to display a wallpaper from the OS:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIScrollbars_Ex.au3"
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#Include <GDIPlus.au3>
#include <WindowsConstants.au3>

$File = "C:\Windows\Web\Wallpaper\Windows\img0.jpg"

$wide = Round((@DesktopWidth / 7) * 5, 0)
$tall = Round(@DesktopHeight * 0.9, 0)

$hGUI = GUICreate("View Large Image", $wide, $tall)

$hImage =  _GDIPlus_ImageLoadFromFile($File)                    ; determine the size of the image
$Width = _GDIPlus_ImageGetWidth($hImage)
$Height = _GDIPlus_ImageGetHeight($hImage)

$hChild_GUI = GUICreate("Child", $wide, $tall, 0, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)

$Pic1 = GUICtrlCreatePic("", -1, -1, $Width, $Height)
GUICtrlSetImage(-1, $File)                                      ; << this should work for a JPG
;_SetBitmap($hChild_GUI, $hImage, 255, $Width, $Height)     ; << this is required for PNGs

$aAperture = _GUIScrollbars_Generate($hChild_GUI , $Width , $Height)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GDIPlus_ShutDown ()

Func _SetBitmap($hGUI, $hImage, $iOpacity, $n_width = 200, $n_height = 200)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $n_width)
    DllStructSetData($tSize, "Y", $n_height)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
EndFunc   ;==>_SetBitmap

Thanks in advance for any nudge.




Share this post

Link to post
Share on other sites

Good point!  That single change enables the JPG to display.  And the scrollbars work as expected.

Any ideas on how to make the PNG method work?  The reason I used a child window is that GUIScrollbars_Generate seemed to require it.

Thanks for your response.


Share this post

Link to post
Share on other sites
11 minutes ago, qwert said:

how to make the PNG method work

Try to use function _GUICtrlPic_Create() from example to function _GDIPlus_BitmapCreateDIBFromBitmap() from help file

; $Pic1 = GUICtrlCreatePic("", -1, -1, $Width, $Height)
; GUICtrlSetImage(-1, $File)
$Pic1 = _GUICtrlPic_Create($File, 0, 0, $Width, $Height)


Share this post

Link to post
Share on other sites


Indeed, that works.  It is not a method I had ever noticed.  I appreciate your help with this ... and I'm glad to have both JPG and PNG methods working.

But, alas, I have again run upon an internal hard limit on the size of images.  The PNG method will display an image with a height of 30,000 pixels, but not one with 36,000 pixels.  I had previously found that JPGs are limited to about 25,000 pixels and was hoping that a PNG was not restricted. 

But my testing now confirms that there is a limit.  I don't know if it's a limit in the vertical dimension ... or a limit in total pixels ... and if there's any setting that can increase the limit.

Can anyone point to documentation for Au3?  Checking Internet sources did not yield a definitive answer for PNGs, only for JPGs.


Share this post

Link to post
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


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.