I’m programming on VBA. I want to know wether an image has transparency (i.e. alpha channel present and transparent pixels). I use the IM command proposed here viewtopic.php?t=18596 :
Code: Select all
convert image.png -alpha on -alpha extract -format "%[fx:mean]" info:
I call this command from VBA, usint "WScript.Shell" :
Code: Select all
Set shellCommand = VBA.CreateObject("WScript.Shell")
cmdLine = “convert image.png -alpha on -alpha extract -format "%[fx:mean]" info: > C:\tempfile.txt”
windowStyle = 0
waitOnReturn = True
returnCode = shellCommand.Run("%comspec% /c " & cmdLine, intWindowStyle, bWaitOnReturn)
I use shellCommand.Run and not shellCommand.Exec, because I want the shell window not to be visible and it seems only feasible with Run.
To get the result of the shell command, I forward it to a text file (I would have preferred to get the result directly, but didn’ find the way to do it).
The problem with the above code is that the tempfile.txt is created, but it is empty. Do you have any idea why ?
By the way I’ve tested the command directly from the DOS command prompt, and it works : the tempfile.txt contains the result.