0
2

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.

Windows 10 にImageMagickをインストール後Excel VBAから動かしてみる

Last updated at Posted at 2021-07-06

目的

以前Windows版ImageMagickをインストール後VBAで試していないことに気が付いたので、試してみる。
※どこかで仕様変更があったようなので、検索記事の日付を見て参考にできるかどうかの判断は必要です
ツール->参照設定->ImageMagickObject 1.0 Type Library を追加後オブジェクトブラウザでメソッドを確認するのが吉かと(古い記事だと存在しないメソッドを使用していたりします)
実行時にはImageMagickObject 1.0 Type Libraryのチェックは必要ない
Changelogを見ると
7.1.0-25 - 2022-02-15
Removed ImageMagickObject because we no longer support this.
なので、バージョン依存で以下は不可です

ダウンロード&インストール

ImageMagick - DownloadよりImageMagick-7.1.0-2-Q16-HDRI-x86-dll.exeをダウンロードする
インストール時 Select Additional Tasks 画面の一番下の
[Install ImageMagickObject OLE Control for VBScript, Visual Basic, and WSH] をチェックする

サンプルプログラム

"C:\Program Files (x86)\ImageMagick-7.1.0-Q16-HDRI\images" 以下の適当な画像のリサイズ&形式の変更を行う

Dim imgMkObj    As Object
Dim imgPath     As String
Dim outPath     As String
Dim msg         As Variant
Dim objFso      As New FileSystemObject
'
Set imgMkObj = CreateObject("ImageMagickObject.MagickImage.1")

imgPath = ActiveWorkbook.Path & "\" & "bluebells_clipped.jpg"
outPath = ActiveWorkbook.Path & "\" & "bluebells_clipped.png"
'    Debug.Print imgPath
'    Debug.Print outPath
'
' すでにファイルが存在する場合事前に削除する
'
If objFso.FileExists(outPath) Then
    objFso.DeleteFile (outPath)
End If

msg = imgMkObj.Convert(imgPath, outPath)

Debug.Print msg
'
' すでにファイルが存在する場合事前に削除する
'
If objFso.FileExists(outPath) Then
    objFso.DeleteFile (outPath)
End If

msg = imgMkObj.Convert("-resize", "400x300", imgPath, outPath)

Debug.Print msg

参考にしたのは以下のサイト

Using Blobs from Excel VBA
[DEV:003-01] ImageMagickをVBAから使う

0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?