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:
IMG_4717-min.JPG


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:
IMG_4719-min.JPG

this is the right real-life aspect

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

Mike1970

Well-Known Member
Licensed User
Longtime User
I'm not sure if you are joking but the second image is a completely different image to the first. Look elsewhere in your code for whatever the problem is.
it's only a different shot -.-

1. i compiled the app
2. I take the shot
3. I changed the line
4. i re-compiled the app
5. i taked another shot of the SAME subject just to show the differences

I'm not stupid .-.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Sorry but I still don't understand your problem?

ok... if you take a closer look to the two images, you can immediately notice that the RESULT image when I use ".Rotate(90)" it is SQUEEZED on the Y Axes (instead of rotated 90° however).

If I remove the ".Rotate(90)" function the image result it's correct, no squeezing, no stretching.

As soon as Windows finishes the update, i try to execute the same app on an iPhone5 with iOS 11 I think
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
The effect is much more obvious in the video than in the original photos, where I still can't really see the stretching despite now knowing what to look for! My guess is that it is due to the EXIF information regarding the camera orientation when the photo was taken.

It is possible that the effect is caused when displaying the photo and not when saving it as the image jpg might contain conflicting width/height/EXIF information but it would need further testing to check this out. First thing I would do is put the image on a PC and display it with several different image viewers and also look at the EXIF data for the normal and the stretched versions.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
where I still can't really see the stretching despite now knowing what to look for!
I put both the images in the first post just to give to all of you a reference. I thought it was clear that the first photo isn't representing the real-world in a correct way ?... compared to the one I classified like "the good one" (the second).
(just compare the height and width of the two images... )


First thing I would do is put the image on a PC and display it with several different image viewers

In the original project, the image file (the same I save in the Photo app of the iPhone) is sent to an FTP Server.
For obvious reasons I did not implemented this in the demo project.

however, the images are displayed in the same way on Pc too, I verified it by downloading the images from the FTP Server
 
Last edited:
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
@agraham i modified the Example by changing the "Cam_complete" function to:

B4X:
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)
            image.WriteToStream(out, 50, "JPEG") 
            out.Close
          
            Dim im As Bitmap = LoadBitmap(File.DirLibrary & "/" & "TestBitmap", "bitmap.jpeg")
            If Switch1.Value Then
                im = im.Rotate(90)
            End If
          
            Dim p As Phone
            p.AddImageToAlbum(im)
        End If
    End If
End Sub

So the image saved to Album is alwasy an image loaded from the memory.
If the switch is on, then before save the image to the Album it rotates

the result is the same... stretch
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Technically should be similar to this
Not necessarily, it depends on how the EXIF data is treated within an Image and written to file.

However you haven't done what I suggested and saved the rotated image to file and then reloaded it to see if it makes a difference. You have only rotated the image in memory. I don't really expect a difference as maybe rotate() is broken but try it anyway.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User

This is the updated function. Same result. when the switch is on, the image is squeezed instead of rotated
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
          
            imageview.ContentMode = imageview.MODE_FIT
            imageview.Bitmap = image
          
            Dim out As OutputStream = File.OpenOutput(File.DirLibrary & "/" & "TestBitmap", "bitmap.jpeg", False)
            image.WriteToStream(out, 50, "JPEG") 
            out.Close
          
            Dim p As Phone
            p.AddImageToAlbum(image)
        End If
    End If
End Sub
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
This is the updated function. Same result. when the switch is on, the image is squeezed instead of rotated
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
         
            imageview.ContentMode = imageview.MODE_FIT
            imageview.Bitmap = image
         
            Dim out As OutputStream = File.OpenOutput(File.DirLibrary & "/" & "TestBitmap", "bitmap.jpeg", False)
            image.WriteToStream(out, 50, "JPEG")
            out.Close
         
            Dim p As Phone
            p.AddImageToAlbum(image)
        End If
    End If
End Sub
Try putting the imageview inside a panel and rotating the panel
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Try putting the imageview inside a panel and rotating the panel

I can't do it for two reasons.
1. I don't know how to rotate a panel ? (no the main problem)
2. I need the FILE, because I need to send the image via FTP then. (the true reason), so I need to actually manipulate the image file.
 
Upvote 0
Top