Sign in to follow this  
Followers 0
Werty

GDIPlus, ignore DPI ?

4 posts in this topic

#1 ·  Posted (edited)

I'm trying to show some pics on the gui using GDIPlus, but they dont show up in full size, they are shrunk.

Example...

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>

$gui = GUICreate("Virginia", 966, 1024)
GUISetState()

_GDIPlus_Startup()
$virginia = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\virginia.jpg")
$hgraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
_GDIPlus_GraphicsDrawImage($hgraphic, $virginia, 0, 0)

_GDIPlus_Shutdown()
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

If I change the DPI of the pics they become bigger (or smaller), but how do I make it just show the pic, ignoring the DPI, showing in pixel size instead, pic being 500 pixels wide should be 500 pixels wide on screen aswell :x

Thanks

/edit

Got it working this way...

_GDIPlus_GraphicsDrawImageRect($hgraphic, $virginia, 0, 0, 500, 242)

..but please tell if there's a better way to do it.

post-58319-0-39352700-1292747324_thumb.j

Edited by Werty

Share this post


Link to post
Share on other sites



Maybe this way:

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>

_GDIPlus_Startup()
$virginia = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\virginia.jpg")
$iW = _GDIPlus_ImageGetWidth($virginia)
$iH = _GDIPlus_ImageGetHeight($virginia)
$gui = GUICreate("Virginia", $iW, $iH)
GUISetState()
$hgraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
_GDIPlus_GraphicsDrawImageRect($hgraphic, $virginia, 0, 0, $iW, $iH)
_GDIPlus_BitmapDispose($virginia)
_GDIPlus_Shutdown()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Exit

You can have a look here, too:

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>

Local $hGUI = GUICreate("Virginia", @DesktopWidth, @DesktopHeight)
GUISetState()

_GDIPlus_Startup()

Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Local $hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\virginia.jpg")
_GDIPlus_BitmapSetResolution($hBitmap, 96, 96)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\virginia96DPI.jpg")

Local $iTop

_GDIPlus_BitmapSetResolution($hBitmap, 300, 300)
$iTop = _GDIPlus_ImageGetHeight($hBitmap)
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)

_GDIPlus_BitmapSetResolution($hBitmap, 96, 96)
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, $iTop)


Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()


Func _GDIPlus_BitmapSetResolution($hBitmap, $nDpiX, $nDpiY)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapSetResolution", "ptr", $hBitmap, "float", $nDpiX, "float", $nDpiY)

    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc

Changing the resolution does not change the physical size of the image.

Share this post


Link to post
Share on other sites

Maybe this way:

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>

_GDIPlus_Startup()
$virginia = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\virginia.jpg")
$iW = _GDIPlus_ImageGetWidth($virginia)
$iH = _GDIPlus_ImageGetHeight($virginia)
$gui = GUICreate("Virginia", $iW, $iH)
GUISetState()
$hgraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
_GDIPlus_GraphicsDrawImageRect($hgraphic, $virginia, 0, 0, $iW, $iH)
_GDIPlus_BitmapDispose($virginia)
_GDIPlus_Shutdown()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Exit

You can have a look here, too:

Br,

UEZ

Thanks, since you use ImageRect also, I guess that is right then.

A question about Dispose(), how important is it, do I need to use it every time to avoid memleaks, or can I use the same variable and just fill it with something else, and then that will take over the mem used ? like..

$virginia = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\virginia.jpg")
;do stuff with it here
$virginia = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\virginia2.jpg")
;do stuff with that also
Etc etc

..or do I have to use Dispose() in between ? like so...

$virginia = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\virginia.jpg")
;do stuff with it here
Bitmap_Dispose($virginia)
$virginia = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\virginia2.jpg")
;do stuff with that also
Bitmap_Dispose($virginia)
Etc etc

?

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
Sign in to follow this  
Followers 0