Sign in to follow this  
Followers 0

png files in autoit

14 posts in this topic

Posted

I've tried in several cases to use a p.ng file in my program and was unsuccessful.

I would try it with GUICtrlCreatePic() and GUICtrlSetImage and so forth. Everytime I would try to use a .png

it would just put a blank space wherever the image was supposed to be.

does autoit support png's?

Share this post


Link to post
Share on other sites



Posted

GDI+ is the key:

#include <GDIPlus.au3>
#include <WinAPI.au3>
_GDIPlus_Startup()
$image=_GDIPlus_ImageLoadFromFile("image.png")
_GDIPlus_ImageSaveToFile($image,"image.jpg")
_WinAPI_DeleteObject($image)
GUICreate("test",300,300)
GUICtrlCreatePic("image.jpg",10,10)
GUISetState()
Do
	$msg=GUIGetMsg()
Until $msg=-3
_GDIPlus_Shutdown()

:)

Share this post


Link to post
Share on other sites

Posted (edited)

So it converts it over to a .jpg?

My image is very deformed in the gui?...

And it lost ALL of its glossiness, and resolution...

I wanted to use .png in the first place so I could have really good looking images.

Edited by nowagain

Share this post


Link to post
Share on other sites

Posted

So it converts it over to a .jpg?

My image is very deformed in the gui?...

And it lost ALL of its glossiness, and resolution...

I wanted to use .png in the first place so I could have really good looking images.

Change to .bmp :)

Share this post


Link to post
Share on other sites

Posted (edited)

Or you could paint the control yourself :)

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
_GDIPlus_Startup()
$image = _GDIPlus_ImageLoadFromFile("image.png")


$hwnd = GUICreate("test", 300, 300)
GUICtrlCreatePic("", 10, 10, 280, 280)
GUISetState()
GUIRegisterMsg($WM_PAINT, "_ReDraw")
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsDrawImageRect($graphics, $image, 10, 10, 280, 280)

Do
	$msg = GUIGetMsg()
Until $msg = -3
_WinAPI_DeleteObject($image)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_Shutdown()

Func _ReDraw()
	_GDIPlus_GraphicsDrawImageRect($graphics, $image, 10, 10, 280, 280)
	Return $GUI_RUNDEFMSG
EndFunc ;==>_ReDraw
Edited by monoceres

Share this post


Link to post
Share on other sites

Posted

That did it :)

Thanks a million.

Share this post


Link to post
Share on other sites

Posted

Or you could paint the control yourself :)

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
_GDIPlus_Startup()
$image = _GDIPlus_ImageLoadFromFile("image.png")


$hwnd = GUICreate("test", 300, 300)
GUICtrlCreatePic("", 10, 10, 280, 280)
GUISetState()
GUIRegisterMsg($WM_PAINT, "_ReDraw")
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsDrawImageRect($graphics, $image, 10, 10, 280, 280)

Do
	$msg = GUIGetMsg()
Until $msg = -3
_WinAPI_DeleteObject($image)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_Shutdown()

Func _ReDraw()
	_GDIPlus_GraphicsDrawImageRect($graphics, $image, 10, 10, 280, 280)
	Return $GUI_RUNDEFMSG
EndFunc;==>_ReDraw
When I use this method whenever I move around my window a blackish border expands around my image and stays there. then i minimize it and it goes a way, but then re-appears when i move my window again...?

Share this post


Link to post
Share on other sites

Posted

Here's the code I am using:

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
_GDIPlus_Startup()
$image = _GDIPlus_ImageLoadFromFile("glass.png")


$hwnd = GUICreate("", 500, 500)
GUICtrlCreatePic("", 20, 20, 24, 26)
GUISetBkColor(0xeef2fd, $hwnd)
GUISetState()
GUIRegisterMsg($WM_PAINT, "_ReDraw")
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsDrawImageRect($graphics, $image, 20, 20, 24, 26)

Do
	$msg = GUIGetMsg()
Until $msg = -3
_WinAPI_DeleteObject($image)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_Shutdown()

Func _ReDraw()
	_GDIPlus_GraphicsDrawImageRect($graphics, $image, 20, 20, 24, 26)
	Return $GUI_RUNDEFMSG
EndFunc;==>_ReDraw

When I run it and move the window containing my .png image a black border forms around it. Is is the re-drawing function? I'm lost and also very new with this GDI+ stuff.

Share this post


Link to post
Share on other sites

Posted

Bump. Does anyone need to see a screenshot?

Share this post


Link to post
Share on other sites

Posted

Try something like:

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
_GDIPlus_Startup()
$image = _GDIPlus_ImageLoadFromFile("glass.png")


$hwnd = GUICreate("", 500, 500)
GUICtrlCreatePic("", 22, 22, 20, 22); Changed here
GUISetBkColor(0xeef2fd, $hwnd) 
GUISetState()
GUIRegisterMsg($WM_PAINT, "_ReDraw")
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsDrawImageRect($graphics, $image, 20, 20, 24, 26)

Do
	$msg = GUIGetMsg()
Until $msg = -3
_WinAPI_DeleteObject($image)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_Shutdown()

Func _ReDraw()
	_GDIPlus_GraphicsDrawImageRect($graphics, $image, 20, 20, 24, 26)
	Return $GUI_RUNDEFMSG
EndFunc;==>_ReDraw

Share this post


Link to post
Share on other sites

Posted

As far as I can see it looks like its solved, but I don't understand why...

You changed the width and height (24,26) to 20,22. How did that fix it?

Share this post


Link to post
Share on other sites

Posted

As far as I can see it looks like its solved, but I don't understand why...

You changed the width and height (24,26) to 20,22. How did that fix it?

Difference by 'GUI Border Width' added, or not.

Share this post


Link to post
Share on other sites

Posted

this was a real old topic dude.

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