0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

VBS 画像ファイルのサイズ(幅×高さ)取得 PNG&TIFF対応

Posted at

LoadPicture関数では失敗してしまう

JPEGだといけるのに、PNGだとエラーになってしまう。
「たかが縦横サイズだけなのに」と絶望しかけていたら、StackOverflowで海外の方が回答されていました!
しかも、ピクセル単位で取得してくれるので下手な計算も必要ありません。
StackOverflow - Need to read width/height from graphics file with VBScript/ASP classic

スクリプト

imgFilePath = "tmp.PNG" 'JPEG、TIFFにも使用できることを確認

' インスタンス作成
Set objImg = CreateObject("WIA.ImageFile")
' ファイルパス指定
objImg.LoadFile(imgFilePath)
' 幅x高さで表示
WScript.Echo(objImg.Width & "x" & objImg.Height & "(ピクセル)")
' インスタンス初期化
Set wia = Nothing

'### または ###
With CreateObject("WIA.imagefile")
    .LoadFile(imgFilePath)
    WScript.Echo(.Width & "x" & .Height & "(ピクセル)")
End With

'### 実行結果 ###
'1920x1080(ピクセル)

参考

StackOverflow - Need to read width/height from graphics file with VBScript/ASP classic
WIA.ImageFileオブジェクトについて(公式)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?