使用VBA和ImageMagick旋转文件夹中的选定图像 [英] Rotate selected images in a folder using VBA and ImageMagick

查看:214
本文介绍了使用VBA和ImageMagick旋转文件夹中的选定图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查文件夹中是否存在我图像的旋转版本,如果不存在,我想使用ImageMagick为我自动执行此操作(或其他程序,如果这样会更好).这是我的代码:

I want to check a folder if a rotated version of my images exists, if it doesn't I want to use ImageMagick to automatically do it for me (or another program if it would be a better option). This is my code:

Dim imageDomain As String
Dim imagePath As String
Dim rotatePath As String
Dim rotateBool As Boolean
Dim imageRotator As Integer
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT Afbeelding FROM Products")

imageDomain = CurrentProject.Path & "\folder\"

If Not (rs.EOF And rs.BOF) Then
    rs.MoveFirst
    Do Until rs.EOF = True

        If Not IsNull(rs!Afbeelding) Then
            rotatePath = imageDomain & "rotate\" & rs!Afbeelding
            rotateBool = Len(Dir(rotatePath))

            If Not rotateBool Then
                imagePath = imageDomain & rs!Afbeelding
                imageRotator = Shell("cmd.exe /c convert.exe -rotate ""270"" " & imagePath & " " & rotatePath)
            End If
        End If

        rs.MoveNext
    Loop
Else
    MsgBox "There are no records in the recordset."
End If

rs.Close
Set rs = Nothing

该代码在shell命令中给出了溢出错误.如何使用VBA使用ImageMagick选择性旋转所需的图像?使用批处理文件会旋转文件夹中的所有图像吗?

The code gives an overflow error at the shell command. How can I selectively rotate the images I want with ImageMagick using VBA? Using a batch file would rotate all images in the folder?

推荐答案

COM +对象可以解决问题.

The COM+ object did the trick.

Dim img As Object
Set img = CreateObject("ImageMagickObject.MagickImage.1")

在循环中:

imageRotator = img.Convert(imagePath, "-rotate", "270", rotatePath)

这篇关于使用VBA和ImageMagick旋转文件夹中的选定图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆