Use of imagemagickobject in vba
Use of ImageMagickObject in VBA
Option Explicit
‘Dim img As New ImageMagickObject.MagickImage
Sub test()
Dim SourceFile As String
Dim DestFile As String
Dim DestFile2 As StringDim msg
‘Dim img As ImageMagickObject.MagickImage ‘ Gives error
Dim img As Object
Set img = CreateObject(« ImageMagickObject.MagickImage.1 »)
Debug.Print typename(img)SourceFile = « C:Program FilesImageMagick-6.6.4-Q16ImageMagickObjectTestsill_meets_gorilla_screen.jpg »
DestFile = « C:ProgramFilesImageMagick-6.6.4-Q16ImageMagickObjectTestsill_meets_gorilla_mogged.jpg »
DestFile2 = « C:Program FilesImageMagick-6.6.4-Q16ImageMagickObjectTestsill_meets_gorilla_mogged2.jpg »
msg = img.Convert(SourceFile, DestFile)
Debug.Print msgmsg = img.Mogrify(« -resize », « 800×600 », DestFile)
Debug.Print msg
msg = img.Convert(DestFile, DestFile2)
Debug.Print msg
End Sub
Sub ScreenCap() ‘WORKS
Dim DestFile As StringDim imObject As Object
DestFile = « C:Program FilesImageMagick-6.6.4-Q16ImageMagickObjectTestscapscreen.jpg »
‘Create ImageMagick Object
Set imObject =CreateObject(« ImageMagickObject.MagickImage.1 »)
‘Copy selected area to clipboard as picture
Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
‘Save clipboard to image named c:image.jpg
imObject.Convert »clipboard:myimage », « », « -quality », « 85 », DestFile
End Sub
Sub ScreenCap2() ‘WORKS – As above but inverts image first
Dim DestFile As String
Dim imObject As Object
DestFile = »C:Program FilesImageMagick-6.6.4-Q16ImageMagickObjectTestscapscreen2.jpg »
‘Create ImageMagick Object
Set imObject = CreateObject(« ImageMagickObject.MagickImage.1 »)
‘Copy selected area toclipboard as picture
Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
‘Save clipboard to image named c:image.jpg
imObject.Convert « clipboard:myimage », « », « -negate », « -quality »,…