代码之家  ›  专栏  ›  技术社区  ›  Arne Clicteur

使用VBA和ImageMagick旋转文件夹中的选定图像

  •  0
  • Arne Clicteur  · 技术社区  · 7 年前

    我想检查一个文件夹,如果存在我的图像的旋转版本,如果不存在,我想使用ImageMagick为我自动执行该操作(如果是更好的选择,可以使用其他程序)。这是我的代码:

    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有选择地旋转所需的图像?使用批处理文件是否会旋转文件夹中的所有图像?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Arne Clicteur    7 年前

    COM+对象成功了。

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

    在循环中:

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