Android Question How rotate a photo already rotate 90 on the device through code?

Computersmith64

Well-Known Member
Licensed User
Longtime User
Try the functions below (untested, but modified from a couple of functions I use in one of my apps).

B4X:
Private Sub saveRotatedImage
    Private bm As Bitmap
    Private input As InputStream
    Private output As OutputStream
    Private buffer() As Byte
   
   
    Try
        input = File.OpenInput([Image Directory], [Image Name])
        bm.Initialize2(input)
        Private bm2 As Bitmap = rotateImage(bm, [rotation value])
        output.InitializeToBytesArray(0)
        bm2.WriteToStream(output, 100, "PNG")
        buffer = output.ToBytesArray
        output = File.OpenOutput([Output Directory], [Output Image Name], False)
        output.WriteBytes(buffer, 0, buffer.Length)
        output.Flush
        output.Close
    Catch
        Log(LastException)
    End Try
End Sub

Public Sub rotateImage(Original As Bitmap, rotateBy) As Bitmap
    Private b2 As BitmapExtended
    
    b2.Initialize("")
    Return b2.rotateBitmap(Original, rotateBy)
   
End Sub

- Colin.
 
Upvote 0
Top