Page 1 of 1
identify image bit depth?
Posted: 21 Apr 2014, 04:38
by Guest
I seek ahk code to identify the bit depth of image files. Any ideas on how to do that?
Re: identify image bit depth?
Posted: 22 Apr 2014, 14:44
by kon
Reference:
how to retrieve the properties of a specified file
Code: Select all
Gui, Add, Text,, Drop images here to test.
Gui, Show, w200 h200
objShell := ComObjCreate("Shell.Application")
return
GuiDropFiles:
Loop, parse, A_GuiEvent, `n
{
SplitPath, A_LoopField, FileName, DirPath
objFolder := objShell.NameSpace(DirPath)
objFolderItem := objFolder.ParseName(FileName)
MsgBox, % objFolder.GetDetailsOf(objFolderItem, 160) ;Bit depth was the 160th property in my tests.
}
return
GuiClose:
ExitApp
Re: identify image bit depth?
Posted: 22 Apr 2014, 22:15
by kon
I tested on a different computer and it seems that bit depth is not always the 160th property. So one way to fix that would be to loop through the properties until bit depth is found:
Code: Select all
Gui, Add, Text,, Drop image files here.
Gui, Show, w200 h200
objShell := ComObjCreate("Shell.Application")
return
GuiDropFiles:
Loop, parse, A_GuiEvent, `n
{
BD := ""
SplitPath, A_LoopField, FileName, DirPath
objFolder := objShell.NameSpace(DirPath)
objFolderItem := objFolder.ParseName(FileName)
Loop 283
if (objFolder.GetDetailsOf(objFolder.Items, A_Index) = "Bit Depth") {
BD := objFolder.GetDetailsOf(objFolderItem, A_Index)
break
}
MsgBox, % "The bit depth of " A_LoopField " is " BD "."
}
return
GuiClose:
ExitApp
Edit: Added
BD := ""
Re: identify image bit depth?
Posted: 23 Apr 2014, 00:12
by joedf
@kon nice!
Re: identify image bit depth?
Posted: 23 Apr 2014, 16:10
by drabne
Works like a charm!
Re: identify image bit depth?
Posted: 24 Apr 2014, 03:26
by just me
Just a look-up table for indices and names of extended properties:
Code: Select all
#NoEnv
SetBatchLines, -1
Gui, Margin, 20, 20
Gui, Add, ListView, w600 r20 Grid vLV +E0x010000, #|Index|Name
Details := GetDetails()
For Index, Name In Details
LV_Add("", A_Index, Index, Name)
Loop, % LV_GetCount("Column")
LV_ModifyCol(A_Index, "AutoHdr")
Gui, Show, , Extended Properties
Return
; ----------------------------------------------------------------------------------------------------------------------
GuiCLose:
ExitApp
; ----------------------------------------------------------------------------------------------------------------------
GetDetails() {
Static MaxGap := 11 ; on WIn 8.1 MU all gaps between named details are less than 4
Shell := ComObjCreate("Shell.Application")
Folder := Shell.NameSpace(0)
Details := [], Gap := 0
While (Gap < MaxGap)
If (Name := Folder.GetDetailsOf(0, A_Index - 1))
Details[A_Index - 1] := Name, Gap := 0
Else
Gap++
Return Details
}
Re: identify image bit depth?
Posted: 18 Jun 2015, 09:10
by BGM
Just Me - that is right handy! The only thing lacking to it is to be able to drag a file onto the window and have it enumerate that file's properties in a fourth column.
Re: identify image bit depth?
Posted: 18 Jun 2015, 09:19
by BGM
Can you fetch bit depth with gdip.ahk ? I don't see any function for bit depth in the gdip library.
Re: identify image bit depth?
Posted: 19 Jun 2015, 15:28
by kon
Bit depth can be specified when
creating a bitmap with
Gdip_CreateBitmap(Width, Height, Format:=0x26200A). 0x26200A will create a 32 bit bitmap, suitable for saving .png, .jpg, etc. files. 0x21808 will create a 24 bit bitmap, which is typically used when saving the bitmap as .bmp. But, I don't know of a way to retrieve the bit depth from a bitmap using GDIP. (That's not to say it isn't possible.)
For others who may happen upon this thread I want to mention that, based on
just me's and my own posts here, I created some functions for retrieving extended file properties. They are available here:
FGP - File Get Properties
In recent months
just me created a lib for
WIA - Windows Image Acquisition (requires Windows Vista or newer). It can be used to retrieve bit depth too. For an example run WIASample.ahk and select "Common Properties" from the menu. (WIA calls it PixelDepth)
Re: identify image bit depth?
Posted: 20 Jun 2015, 02:45
by just me
Once you loaded the image file into a GDI+ bitmap/image object you can call Gdip_GetImagePixelFormat(pBitmap). The second byte of the returned Format value contains the bit depth: BitDepth := (Format >> 8) & 0xFF
Re: identify image bit depth?
Posted: 20 Jun 2015, 14:59
by BGM
just me - thank you!