here is my solution using ILC_ORIGINALSIZE.
Now Im wondering is it possible to center image inside tile because it is always aligned to left up corner.
Code: Select all
#include <GDIp>
Gdip_Startup()
#Singleinstance, force
ILC_COLOR32 := 0x20
ILC_ORIGINALSIZE := 0x00010000
dir := "D:\x\ClearedText\tesseract\old\oem0_psm6_20180114221528_DONE\letters\105"
isizew := 128
isizeh := 128
hIml := ImageList_Create(isizew, isizeh, ILC_COLOR32|ILC_ORIGINALSIZE, 100, 100)
;==============================================================
Gui, Add, ListView, w600 h600 HWNDhLV grid, icon&A_Index|w|h
LV_SetImageList(hIml,1) ; list mode (default)
;==============================================================
;Gui, Add, ListView, w600 h600 HWNDhLV icon, icon&A_Index|w|h
;LV_SetImageList(hIml,0) ; icon mode
;==============================================================
Gui, Show, autosize
loop,% dir "\*.bmp"
{
if (A_Index<25)
continue
Gdip_GetImageDimensionsFile(A_LoopFileFullPath,w,h)
m := (w<h ? isizeh/h : isizew/w)
hIcon := API_LoadImage(A_LoopFileFullPath, 0, round(w*m), round(h*m), 0x10) ; fit to isize
;hIcon := API_LoadImage(A_LoopFileFullPath, 0, w, h, 0x10) ; use oryginal size but crop image if larger than isize
i := ImageList_Add( hIml, hIcon )
;LV_Add("Icon" A_Index-1,A_Index,A_Index)
LV_Add("Icon" . i+1, A_Index,w,h)
if (i==1)
LV_ModifyCol()
;msgbox,% i
}
return
ListView_SetImageList( hwnd, hIml, iImageList=0) {
SendMessage, 0x1000+3, iImageList, hIml, , ahk_id %hwnd%
return ErrorLevel
}
ImageList_Create(cx,cy,flags,cInitial,cGrow){
return DllCall("comctl32.dll\ImageList_Create", "int", cx, "int", cy, "uint", flags, "int", cInitial, "int", cGrow)
}
ImageList_Add(hIml, hbmImage, hbmMask=""){
return DllCall("comctl32.dll\ImageList_Add", "uint", hIml, "uint",hbmImage, "uint", hbmMask)
}
ImageList_AddIcon(hIml, hIcon) {
return DllCall("comctl32.dll\ImageList_ReplaceIcon", "uint", hIml, "int", -1, "uint", hIcon)
}
API_ExtractIcon(Icon, Idx=0){
return DllCall("shell32\ExtractIconA", "UInt", 0, "Str", Icon, "UInt",Idx)
}
API_LoadImage(pPath, uType, cxDesired, cyDesired, fuLoad) {
return, DllCall( "LoadImage", "uint", 0, "str", pPath, "uint", uType, "int", cxDesired, "int", cyDesired, "uint", fuLoad)
}
LoadIcon(Filename, IconNumber, IconSize) {
DllCall("PrivateExtractIcons"
,"str",Filename,"int",IconNumber-1,"int",IconSize,"int",IconSize
,"uint*",h_icon,"uint*",0,"uint",1,"uint",0,"int")
if !ErrorLevel
return h_icon
}
Gdip_GetImageDimensionsFile(file, ByRef Width, ByRef Height){
pBitmap := Gdip_CreateBitmapFromFile(file)
Gdip_GetImageDimensions(pBitmap,Width,Height)
Gdip_DisposeImage(pBitmap)
}
map(x, in_min, in_max, out_min, out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
}