Jump to content

Stretched Image on GDI+ _GDIPlus_GraphicsDrawImage() Function


UEZ
 Share

Recommended Posts

When I want to use _GDIPlus_GraphicsDrawImage() for displaying images then some images will be displayed in window stretched!

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)
Global $hWnd1, $hWnd2, $hGraphic, $file, $hImage, $hMatrix
Global $iX, $iY

$file = FileOpenDialog("Select image to load", @ScriptDir, "Images (*.jpg;*.bmp)")

_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile($file)

$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)

$hWnd1 = GUICreate("_GDIPlus_GraphicsDrawImage", $iX, $iY, @DesktopWidth / 2 - $iX - 10)
GUISetState()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd1)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0) ;is not working properly with some images
;_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX, $iY) ;is working
_GDIPlus_ImageDispose($hImage)

$hWnd2 = GUICreate("GUICtrlCreatePic", $iX, $iY, @DesktopWidth / 2 + 10)
GUISetBkColor(0)
GUICtrlCreatePic($file, 0, 0, $iX, $iY)
GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Do
Until Not Sleep(10000000)

Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
EndFunc

I attached 2 images, both images will be displayed stretched (zoomed) with _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0) function but not with GUICtrlCreatePic($file, 0, 0, $iX, $iY)!

Why?

I tried to re-save the images but no success! I couldn't see the difference between the jpg files (formats)

Thanks and merry x-mas!

UEZ

post-29844-12662410020627_thumb.jpg

post-29844-1266241007917_thumb.jpg

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

I think the problem is in the picture. Try to resave Eye.jpg and everything will be OK.

Intel.jpg was originally in BMP format which will be displayed stretched (zoomed)!

Thanks,

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

  • 1 month later...

Solution is to use _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX, $iY) instead! I don't know why it is not working on some images with _GDIPlus_GraphicsDrawImage() but anyway...

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