iOS Question Image.Rotate Strange behavior

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone.

From today the instruction .Rotate for a bitmap is behaving in a strange way.
I think the only thing changed is that I update to iOS 14.3.

My tests
The code
B4X:
Sub Cam_Complete(Success As Boolean, Image as Bitmap, VideoPath As String)
    If Success Then
        If Image.IsInitialized Then
            btnDelete_Click 'delete previous chached images'
         
            imgCL.ContentMode = imgCL.MODE_FIT
            imgCL.Bitmap = Image

            Dim out as OutputStream = File.OpenOutput(path, fname, False)
            Image.Rotate(90).WriteToStream(out, 50, "JPEG")
         
            Dim p as Phone
            p.AddImageToAlbum(LoadBitmap(path, fname))
         
        End If
    End If
End Sub

This code ☝result is this image:


I changed the line 10 to:
B4X:
Image.WriteToStream(out, 50, "JPEG")
then I recompiled the app, and take another shot.

and the result was this:

this is the right real-life aspect

Small video and project example in post #8
 
Last edited:

angel_

Well-Known Member
Licensed User
Longtime User
Without testing

B4X:
Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")
    
    pnl = xui.CreatePanel("")
    Page1.RootPanel.AddView(pnl, 0, 0, 200dip, 200dip)
    imageview.Initialize("img")
    pnl.AddView(imageview, 0, 0, pnl.Width, pnl.Height)

    NavControl.ShowPage(Page1)
    
    If Not(File.Exists(File.DirLibrary, "TestBitmap")) Then
        File.MakeDir(File.DirLibrary, "TestBitmap")
    End If
End Sub

Sub Cam_Complete (Success As Boolean, image As Bitmap, VideoPath As String)
    If Success Then
        If image.IsInitialized Then
            
            imageview.ContentMode = imageview.MODE_FIT
            imageview.Bitmap = image
            
            Dim out As OutputStream = File.OpenOutput(File.DirLibrary & "/" & "TestBitmap", "bitmap.jpeg", False)
            If Switch1.Value Then
                pnl.Rotation = 90
                Dim im As Bitmap = pnl.Snapshot

                im.WriteToStream(out, 50, "JPEG")
            Else
                image.WriteToStream(out, 50, "JPEG")
            End If           
            out.Close
            
            Dim p As Phone
            p.AddImageToAlbum(LoadBitmap(File.DirLibrary & "/" & "TestBitmap", "bitmap.jpeg"))
        End If
    End If
End Sub
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Thay doesn't really change anything. Read it back after writing it before adding it to the album

Actually that should work as you intended, however....
tried like so too -> No change

B4X:
Sub Cam_Complete (Success As Boolean, image As Bitmap, VideoPath As String)
    If Success Then
        If image.IsInitialized Then
                        
            If Switch1.Value Then
                image = image.Rotate(90)
            End If
                        
            Dim out As OutputStream = File.OpenOutput(File.DirLibrary & "/" & "TestBitmap", "bitmap.jpeg", False)
            image.WriteToStream(out, 50, "JPEG")   
            out.Close
            
            imageview.ContentMode = imageview.MODE_FIT
            imageview.Bitmap = image
            
            Dim inp As InputStream = File.OpenInput(File.DirLibrary & "/" & "TestBitmap", "bitmap.jpeg")
            Dim im As Bitmap
            im.Initialize2(inp)
            inp.Close
            
            Dim p As Phone
            p.AddImageToAlbum(im)
        End If
    End If
End Sub
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Actually that should work as you intended
No it doesn't, but your latest one does and indeed it looks like Rotate() is borked That's providing of course that it is not an album problem which you can easily confirm by looking at the saved rotated file in a couple of other image viewers.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User

I tried.
the result was that the image was correctly rotated in the preview in the app, BUT it save to the library an image NOT rotated and with two white borders on left and right.

Preview OK


The first image in red it the one with the switch OFF, the second in red is the one with the switch ON.



Thanks for your effort! and also thanks for have let me know the ".Rotation" and ".Snapshot" for b4xview, they could be useful in future .. even if them should have worked in this case
 
Last edited:
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
No it doesn't, but your latest one does and indeed it looks like Rotate() is borked That's providing of course that it is not an album problem which you can easily confirm by looking at the saved rotated file in a couple of other image viewers.
yes but, if ".Rotate" had worked properly all the tests I've done should have worked ok...
this is an annoying problem :/
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…