dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] problem with rotate image using WIA

  1. #1

    Thread Starter
    Addicted Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Posts
    190

    Resolved [RESOLVED] problem with rotate image using WIA

    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 ?

    error :

    Name:  err.jpg
Views: 97
Size:  17.6 KB

    and i try use sample code from microsoft like this : (https://msdn.microsoft.com/en-us/lib...itemRotateFlip)

    Code:
    
    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.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,965

    Re: problem with rotate image using WIA

    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
    Name:  sshot.png
Views: 70
Size:  1.7 KB
    Attached Files Attached Files

  3. #3

    Thread Starter
    Addicted Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Posts
    190

    Post Re: problem with rotate image using WIA

    hi i tested your code too and again same error.

    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?
    Attached Files Attached Files
    • File Type: zip 0.zip (171.9 KB, 14 views)

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,965

    Re: problem with rotate image using WIA

    There must be something unique about the file. I tried a larger JPEG and it works fine.

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,539

    Re: problem with rotate image using WIA

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width