hi i hv a image name as 0.jpg and i want rotate and save with wia but this source code show error.
refrences added in vb : microsoft windows image acquisition library v2.0.
Code:
Private Sub Command3_Click()
Call WIA_RotateImage(App.Path & "\0.jpg", App.Path & "\0r.jpg", 90)
End Sub
Public sub WIA_RotateImage(sInitialImage As String, sOutputImage As String, lRotAng As Long)
Dim Img As New ImageFile
Dim ip As New ImageProcess
Img.LoadFile sInitialImage
ip.Filters.Add ip.FilterInfos("RotateFlip").FilterID
ip.Filters(1).Properties("RotationAngle").Value = lRotAng
Set Img = ip.Apply(Img)
Img.SaveFile sOutputImage
End Sub
why this code show this error and how can fix it ?
Dim Img 'As ImageFile
Dim IP 'As ImageProcess
Set Img = CreateObject("WIA.ImageFile")
Set IP = CreateObject("WIA.ImageProcess")
Img.LoadFile "C:\WINDOWS\Web\Wallpaper\Bliss.bmp"
IP.Filters.Add IP.FilterInfos("RotateFlip").FilterID
IP.Filters(1).Properties("RotationAngle") = 90
Set Img = IP.Apply(Img)
Img.SaveFile "C:\WINDOWS\Web\Wallpaper\Bliss90.bmp"
but same error.
Last edited by Black_Storm; Feb 14th, 2018 at 09:15 AM.
Seems to work fine here. Not based on a cobbled up scripting example but I think I'm doing the very same thing:
Code:
Option Explicit
Private Sub Form_Load()
Dim Original As WIA.ImageFile
Dim Rotated As WIA.ImageFile
Set Original = New WIA.ImageFile
Original.LoadFile "Beany.bmp"
Image1.Picture = Original.FileData.Picture
With New WIA.ImageProcess
.Filters.Add .FilterInfos("RotateFlip").FilterID
.Filters(1).Properties("RotationAngle") = 90
Set Rotated = .Apply(Original)
With Image2
.Left = Image1.Left + Image1.Width
.Picture = Rotated.FileData.Picture
End With
.Filters(1).Properties("RotationAngle") = 180
Set Rotated = .Apply(Original)
With Image3
.Left = Image2.Left + Image2.Width
.Picture = Rotated.FileData.Picture
End With
.Filters(1).Properties("RotationAngle") = 270
Set Rotated = .Apply(Original)
With Image4
.Left = Image3.Left + Image3.Width
.Picture = Rotated.FileData.Picture
End With
End With
On Error Resume Next
Kill "BeanyRotated.bmp"
On Error GoTo 0
Rotated.SaveFile "BeanyRotated.bmp"
End Sub
i attached a simple image use for rotate and check it please,whats that problem?
i like use wia to can rotate images but why not work like this attached sample? and how can fix it to can use like this image?
I agree, something about that version of jpg file.
Just as a quick work around I used a picturebox to load the jpg and save as a bitmap, and the loaded bitmap version rotated fine
Code:
Private Sub Form_Load()
Dim Original As WIA.ImageFile
Dim Rotated As WIA.ImageFile
Set Original = New WIA.ImageFile
'Picturebox has AutoSize=True, AutoRedraw=True, Visible=False
Picture1.Picture = LoadPicture("0.jpg") 'load the jpg
SavePicture Picture1.Image, "0.bmp" 'save it as a bmp
' Original.LoadFile "Beany.bmp"
Original.LoadFile "0.bmp" 'load the bmp version
Image1.Picture = Original.FileData.Picture
'....
You could probably change the jpg to a bitmap in memory so wouldn't need a picturebox, but I don't have the expertise in that area.