identify image bit depth? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Guest

identify image bit depth?

21 Apr 2014, 04:38

I seek ahk code to identify the bit depth of image files. Any ideas on how to do that?
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: identify image bit depth?

22 Apr 2014, 14:44

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
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: identify image bit depth?

22 Apr 2014, 22:15

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 := ""
Last edited by kon on 23 Apr 2014, 09:51, edited 2 times in total.
User avatar
joedf
Posts: 8589
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: identify image bit depth?

23 Apr 2014, 00:12

@kon nice!
just me
Posts: 8600
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: identify image bit depth?

24 Apr 2014, 03:26

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
}
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: identify image bit depth?

18 Jun 2015, 09:10

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.
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: identify image bit depth?

18 Jun 2015, 09:19

Can you fetch bit depth with gdip.ahk ? I don't see any function for bit depth in the gdip library.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: identify image bit depth?  Topic is solved

19 Jun 2015, 15:28

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)
just me
Posts: 8600
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: identify image bit depth?

20 Jun 2015, 02:45

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

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot] and 62 guests