il_loadimage.ahk:
/* ************ * IL_LOADIMAGE_VERSION = 1.30 * by foom * * v1.00 - 28.05.06 * -Released * v1.10 - 28.05.06 * -Rewrote the function to add positioning params * v1.16 - 29.05.06 * -Changed the way positioning works. Much more felxible now. * v1.30 - 03.06.06 * -Added cleanup routines to main function. * -Changed DeleteDC to ReleaseDC. * -Changed how shutdown works. Look inside the examplescript for how to use it. * -The defaultimage will now be created by il_init(). * * Requirements: * *Min. AHKVersion = 1.0.43.08 * *This script needs the latest(April 18, 2006) DevIL.dll ILU.dll, ILUT.dll to run. * You can get them here "http://openil.sourceforge.net" if you don't have them allready * and place them into your scripts directory. * * Planned: * *If a function like this "http://www.autohotkey.com/forum/viewtopic.php?t=9904" will be inplemented in AHK * it will be even eaier to use this script because one would not have to find the name of the control with windowspy. * *Create a function which will wrap the "Gui, Add, Pic" command * * Comments: * *Originaly i had the idea to load images with IL and draw them with GDI functions * which wouldn't be comfortable since WM_PAINT messages would need to be used to redraw the image. * Thanks to PhiLho who came up with this idea "http://www.autohotkey.com/forum/viewtopic.php?t=9932" * and Chris who came up with a solution it turned out pretty easy in relation to my first approach. ******************************************************** */ ;_file is the name of the image. ;_static is the name of the picturecontrol. You can find it with the windowspy/AU3_Spy utility. ;_vName is unused now but would simplyfy and replace the use of _static if hwnd could be retrieved thru _vName. ;_x _y _w _h are selfexplantionary. ;""(blank) for any posparam leaves the pos/size as is. -1 for _w or _h will preserve aspectratio while -1 for both will load the image at the original size. ;_GuiNum is the number of the Gui to work in (optional) ;bShutdown is only used to free recources. The only valid value for this param is the string "shutdown". ;Please look into the examplescript for instructions on how to use it. il_loadimage(_file,_static,_x,_y,_w,_h,_GuiNum=1,_bShutdown="") { ;IL_IMAGE_WIDTH = 0x0DE4 ;IL_IMAGE_HEIGHT = 0x0DE5 ;illoadimage = DevIL\ilLoadImage ;ilgetinteger = DevIL\ilGetInteger global hMod_ILUT ;remember the handle between calls and save a copy for cleanup static il_hbitmap old_il_hbitmap:=il_hBitmap ;handle shutdown ;use the il_loadimage function to do the big cleanup since the handles are declared private if (_bShutdown = "shutdown") { il_shutdown(il_hBitmap,hMod_ILUT) return } Gui %_GuiNum%: +LastFound ControlGet, hStatic, Hwnd,, %_static% GuiControlGet, _StaticSize, Pos, %_static% ;create a DC to put our hBitmap in. il_ScreenDC:=DllCall("GetDC", uint, hStatic) ;load image from disk and create a hbitmap from it. DllCall("DevIL\ilLoadImage", str, _file) il_hBitmap:=DllCall("ILUT\ilutConvertToHBitmap", uInt, il_ScreenDC) ;il_hBitmap:=DllCall("ILUT\ilutWinLoadImage", str, _file, uInt, il_ScreenDC) ;place the hbitmap into the static SendMessage, 0x172, 0, il_hBitmap, ,ahk_id %hStatic% ; 0x172 is STM_SETIMAGE if errorlevel ; get the returned hbitmap for cleanup old_hbitmap:=errorlevel ;compute size il_w:=DllCall("DevIL\ilGetInteger", uInt, 0x0DE4) il_h:=DllCall("DevIL\ilGetInteger", uInt, 0x0DE5) if (_w=-1 and _h=-1) { _StaticSizeW:=il_w _StaticSizeH:=il_h } else if (_w=-1 or _h=-1) { if _h= _h=%_StaticSizeH% if _w= _w=%_StaticSizeW% if _w=-1 _w:=round(il_w/(il_h/_h)) if _h=-1 _h:=round(il_h/(il_w/_w)) } if _w>=0 _StaticSizeW:=_w if _h>=0 _StaticSizeH:=_h if _x!= _StaticSizeX:=_x if _y!= _StaticSizeY:=_y GuiControl, MoveDraw, %_static%, x%_StaticSizeX% y%_StaticSizeY% w%_StaticSizeW% h%_StaticSizeH% ;cleanup if ( old_hbitmap and (old_hbitmap != il_hbitmap) ) { ret:=DllCall("DeleteObject", uInt,old_hbitmap) ;msgbox, `nnew hBitmap: %il_hbitmap% `nold hBitmap: %old_hbitmap% `ndeleted successfull: %ret% `nerrorelevel: %errorlevel% } if ( old_il_hbitmap and (old_il_hbitmap != il_hbitmap) ) { ret:=DllCall("DeleteObject", uInt,old_il_hbitmap) ;msgbox, `nnew hBitmap: %il_hbitmap% `nold hBitmap: %old_il_hbitmap% `ndeleted successfull: %ret% `nerrorelevel: %errorlevel% } if il_ScreenDC { ret:=DllCall("ReleaseDC", UInt,hStatic, UInt,old_il_ScreenDC) ;msgbox, `nnew DC: %il_ScreenDC% `nold DC: %old_il_ScreenDC% `ndeleted successfull: %ret% `nerrorelevel: %errorlevel% } } ;############################################################ ;This does not work ATM, don't touch! ; il_getDims(_file,_p2) ; { ; DllCall("DevIL\ilBindImage", uInt, 2) ; DllCall("DevIL\ilLoadImage", str, _file) ; ; if _p2 = w ; result:=DllCall("DevIL\ilGetInteger", uInt, 0x0DE4) ; else if _p2 = h ; result:=DllCall("DevIL\ilGetInteger", uInt, 0x0DE5) ; ; DllCall("DevIL\ilBindImage", uInt, 1) ; ; return result ; } ;############################################################ ;Initialize IL il_init() { ; ILUT_WIN32 = 2 ; IL_ORIGIN_MODE = 0x0603 ; IL_ORIGIN_UPPER_LEFT = 0x0602 ; IL_ORIGIN_SET = 0x0600 ; IL_FORMAT_SET = 0x0610 ; ilinit = DevIL\ilInit ; ilenable = DevIL\ilEnable ; ilsetinteger = DevIL\ilSetInteger ; ilutinit = ILUT\ilutInit ; ilutrenderer = ILUT\ilutRenderer ; ilutwinloadimage = ILUT\ilutWinLoadImage hMod_ILUT := DllCall("LoadLibrary", "str", "ILUT.dll") ;hMod_DevIL := DllCall("LoadLibrary", "str", "DevIL.dll") DllCall("DevIL\ilInit") DllCall("ILUT\ilutInit") DllCall("ILUT\ilutRenderer", uint,2) DllCall("DevIL\ilEnable", uint, 0x0610) DllCall("DevIL\ilEnable", uint, 0x0600) DllCall("DevIL\ilSetInteger", uint, 0x0603, uint, 0x0602) DllCall("DevIL\ilGenImages", uInt, 1, uInt, 1) DllCall("DevIL\ilBindImage", uInt, 1) IfNotExist, iltmp.jpg { DllCall("DevIL\ilDefaultImage") DllCall("DevIL\ilSaveImage", str, "iltmp.jpg") } } ;this function is used internal by il_loadimage and is only here not to clutter the main function too much. il_shutdown(il_hBitmap,hMod_ILUT) { DllCall("DeleteObject", UInt,il_hBitmap) ;DllCall("DeleteDC", UInt,0, UInt,il_ScreenDC) ;DllCall("FreeLibrary", "UInt", hMod_DevIL) DllCall("FreeLibrary", "UInt", hMod_ILUT) } ;http://openil.sourceforge.net/docs/index.php for technical information on IL
il_imageload_example.ahk:
#singleinstance force #include il_loadimage.ahk ;init IL. Put that function at the top of your script. il_init() ;load an image the usual ahkway first. Il_init() will create iltmp.jpg in %A_WorkingDir%. ;This is necessary since we will use the control this creates to put our image inside. Gui, -Margin BackgroundTrans Gui, Add, Picture, x y w640 h640 vthepicture, iltmp.jpg ;using our iltmp.jpg return !+l:: ;DevIL supports following formats for loading: ;.bmp, .cut, .dds, .doom, .gif, .ico, .jpg, .lbm, .mdl, .mng, .pal, .pbm, .pcd, .pcx, .pgm, .pic, .png, .ppm, .psd, .psp, .raw, .sgi, .tga and .tif .hdr ;*Note* ;Animated gifs are not supported in il_loadimage. It will only load the first frame. FileSelectFile, aFile, , , Some Files DevIL supports..., Images (*.tga; *.psd; *.jpg; *.png; *.bmp; *.gif; *.tif; *.dds) If !aFile return il_loadimage(aFile,"static1","","",640,-1) Gui, Show, center autosize return ^!l:: aFile= FileSelectFile, aFile, , , Load windows XP supported formats..., Images (*.jpg; *.png; *.bmp; *.gif; *.tif;) If !aFile return GuiControl, , thepicture, *w640 *h-1 %aFile% Gui, Show, center autosize return GuiClose: ;cleanup/release stuff ;use the il_loadimage function in the following manner to release the resources used by the il_loadimage.ahk script il_loadimage(0,0,0,0,0,0,0,"shutdown") ExitApp return ;http://openil.sourceforge.net/docs/index.php for technical information on IL
Here you can download a .zip with the scrits, the DevIL bins so that you can test it right away.
DOWNLOAD
***Note***
If you have images that you cannot load please zip and upload them somewhere and post a link to them so that i can analyse them.
"DO NOT" upload them to imageshack or any other "file hoster" as raw imagefiles since they compress the images. Upload them as zip,rar,7z.