Jump to content

GDI image overflow


Skitty
 Share

Recommended Posts

I don't know how to explain this accurately, but I'm trying to create an image over a preexisting gui after hiding all the controls in it so they wont show up over the image and then use the image as a control to delete the image control and unhide the controls.

Local $Pos = WinGetPos($gui)
Local $Pic1 = GUICtrlCreatePic("", 0, 0, $Pos[2], $Pos[3])
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)

_GDIPlus_Startup()
$hMem = _MemGlobalAllocFromBinary($ResData)
$hImage = _GDIPlus_ImageLoadFromHGlobal($hMem)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_GDIPlus_ImageDispose($hImage)
_GUICtrlStatic_SetImage($Pic1, $hBitmap)

Problem is that in order to see the full image, you'd have to resize the gui so the picture does not overflow, else you will just see the upper left side of the image, how can I stop that without having to create a child gui window and use that one?

I got these functions from a post by progandy.

Edited by THAT1ANONYMOUSEDUDE
Link to comment
Share on other sites

You can also resize the image to fit into your GUI and display it accordingly.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

You can also resize the image to fit into your GUI and display it accordingly.

Br,

UEZ

That's where I'm hitting the wall, I don't know how to do that, the image automatically displays appropriately if I re-size the gui manually, but the image is initially overflowing.

Here's a picture that can hopefully explain itself a little better~

Posted Image

The above window is the gui in its normal size, but when I resize the gui to be smaller or bigger, that's when the image shows up the way it is supposed to look.

Edited by THAT1ANONYMOUSEDUDE
Link to comment
Share on other sites

I don't know whether this is useful for you:

;coded by UEZ 2011
#include <guiconstantsex.au3>
#include <gdiplus.au3>
#include <windowsconstants.au3>

Global Const $IMAGE_BITMAP = 0
Global Const $STM_SETIMAGE = 0x0172
Global $msg
_GDIPlus_Startup()
Global Const $png = StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUITorus.png")
Global Const $hImage = _GDIPlus_ImageLoadFromFile($png)
Global Const $iW = _GDIPlus_ImageGetWidth($hImage)
Global Const $iH = _GDIPlus_ImageGetHeight($hImage)
Global Const $hGUI = GUICreate("Display PNG Image in picture control", $iW, $iH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME))
Global Const $idPic = GUICtrlCreatePic("", 0, 0, $iW, $iH)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
Global Const $Bmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $Bmp))
GUISetState()

While True
    $msg = GUIGetMsg()
    Switch $msg
        Case $idPic
            MsgBox(0, "Information", "PNG image was clicked")
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($Bmp)
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_Shutdown()
            GUIDelete($hGUI)
            Exit
    EndSwitch
WEnd

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks for the help. I appreciate it.

But what I'm doing is loading images from an sqlite database using so I don't really want to have to extract the image and load it from a file, even though it would probably be better I do so, only problem seems to be that the image is initially overflowing unless I create a seperate gui gor the picture control, which is not desirable at all, but it's a little confusing since it works o a fresh gui and not on the parent gui.

Func Preview($ID)
Local $ResData, $hMem, $hImage, $hBitmap
Local $retarr
If _SQLite_QuerySingleRow($db,"SELECT Img FROM optAirPorts WHERE id='"&$id&"'",$retarr) == $SQLITE_OK Then
  If $retarr[0] == "" Then
   MsgBox(0,"Error","No image preview...")
   Return SetError(1,0,0)
  Else
   $ResData = Binary($retarr[0])
  EndIf
EndIf
Local $Pos = WinGetPos($gui)
Local $Pic1 = GUICtrlCreatePic("", 0, 0, $Pos[2], $Pos[3])
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
_GDIPlus_Startup()
$hMem = _MemGlobalAllocFromBinary($ResData)
$hImage = _GDIPlus_ImageLoadFromHGlobal($hMem)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_GDIPlus_ImageDispose($hImage)
_WinAPI_RedrawWindow($gui)
_GUICtrlStatic_SetImage($Pic1, $hBitmap)
While 1
  Switch GUIGetMsg()
   Case $Pic1
   ExitLoop
  EndSwitch
WEnd
GUICtrlDelete($Pic1)
_GDIPlus_Shutdown()
Return 1
EndFunc
Edited by THAT1ANONYMOUSEDUDE
Link to comment
Share on other sites

So you want to fit the image to the window or the window to the image size?

Because your are fitting the image to the windows size and thus the image will be distorted.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

So you want to fit the image to the window or the window to the image size?

Because your are fitting the image to the windows size and thus the image will be distorted.

Br,

UEZ

Yeah, I'm trying to fit the image to the window size, it seems to work if I create a gui, load the image to the picture control that is the same size as the gui and then set it to @SW_SHOW however, I cannot say the same for the parent gui, the image will show as it does in the spoiler image I posted above, showing only a portion of the upper left area.

The GUI initially has the "Dock_Auto" state set on and if I re-size the thing, suddenly the image displays as it should.

Edit: HA!! Got it!

I was looking at after you mentioned that and saw the "_GDIPlus_ImageGetWidth()" function so I tried it and this works.

You're right, I guess by making the control the size of the image and then resizing it quickly to the size of the gui was what I should have been doing.

Func Preview($ID)
Local $ResData, $hMem, $hImage, $hBitmap
Local $retarr
If _SQLite_QuerySingleRow($db,"SELECT Img FROM optAirPorts WHERE id='"&$id&"'",$retarr) == $SQLITE_OK Then
  If $retarr[0] == "" Then
   MsgBox(0,"Error","No image preview...")
   Return SetError(1,0,0)
  Else
   $ResData = Binary($retarr[0])
  EndIf
EndIf
_GDIPlus_Startup()
$hMem = _MemGlobalAllocFromBinary($ResData)
$hImage = _GDIPlus_ImageLoadFromHGlobal($hMem)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
Local $W = _GDIPlus_ImageGetWidth($hImage)
Local $H = _GDIPlus_ImageGetHeight($hImage)
_GDIPlus_ImageDispose($hImage)
Local $Pos = WinGetPos($gui)
Local $Pic1 = GUICtrlCreatePic("", 0, 0, $W, $H)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
_GUICtrlStatic_SetImage($Pic1, $hBitmap)
GUICtrlSetPos($Pic1,0,0,$Pos[2],$Pos[3])
While 1
  Switch GUIGetMsg()
   Case $Pic1
   ExitLoop
  EndSwitch
WEnd
GUICtrlDelete($Pic1)
_GDIPlus_Shutdown()
Return 1
EndFunc
Edited by THAT1ANONYMOUSEDUDE
Link to comment
Share on other sites

I would use WinGetClientSize() instead of WinGetPos() to get the client size instead of the whole GUI and you don't need _GDIPlus_ImageGetWidth() / _GDIPlus_ImageGetHeigth() functions!

...
    _GDIPlus_Startup()
    $hMem = _MemGlobalAllocFromBinary($ResData)
    $hImage = _GDIPlus_ImageLoadFromHGlobal($hMem)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageDispose($hImage)
    Local $Pos = WinGetClientSize($gui)
    Local $Pic1 = GUICtrlCreatePic("", 0, 0)
    GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
    _GUICtrlStatic_SetImage($Pic1, $hBitmap)
    _WinAPI_DeleteObject($hBitmap)
    GUICtrlSetPos($Pic1,0,0,$Pos[0],$Pos[1])
...

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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