我想检查一个文件夹,如果我的图像的旋转版本存在,如果不存在我想使用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所需的图像?使用批处理文件会旋转文件夹中的所有图像?
COM +对象完成了这个伎俩。
Dim img As Object
Set img = CreateObject("ImageMagickObject.MagickImage.1")
在循环:
imageRotator = img.Convert(imagePath, "-rotate", "270", rotatePath)