Sub button1_click
masterpic.Initialize(dirname,filename)
angle=findangle(dirname,filename)
rotatepicture(angle)
ImageView.Bitmap=masterpic
End Sub
Sub findangle(dir As String, Filename As String) As Int
Dim retValue As Int = 0
Dim filepath As String
Dim exif As ExifData
filepath = dir & "/" & Filename
exif.Initialize("", filepath)
Dim w As Int = exif.getAttributeInt (exif.TAG_ORIENTATION, 0)
If w = exif.ORIENTATION_NORMAL Then retValue = 0
If w = exif.ORIENTATION_ROTATE_90 Then retValue = 90
If w = exif.ORIENTATION_ROTATE_180 Then retValue = 180
If w = exif.ORIENTATION_ROTATE_270 Then retValue = 270
Return retValue
End Sub
Sub rotatepicture( angle As Int)
Dim bb As Bitmap
Dim pwo As Int
Dim sqp As Int
Dim pho As Int
Dim recto As Rect
Dim c As Canvas
pwo = masterpic.Width
pho = masterpic.Height
'pwo=100
'pho=133
sqp = pwo 'for square imaqe
If pwo <> pho Then
'set longer side
sqp = pho
If pwo > pho Then sqp = pwo
'first RESIZE to square
bb = CreateScaledBitmap (masterpic, sqp, sqp, True)
End If
bb.InitializeMutable(sqp,sqp)
recto.Initialize(0, 0,sqp,sqp)
'ROTATE masterPic into bb
c.Initialize2(bb)
c.DrawBitmapRotated(masterpic, Null, recto, angle) 'Draw the new image
masterpic.Initialize3(bb)
'RESIZE back inverse, if pic was not square
If pwo <> pho Then
masterpic = CreateScaledBitmap (bb, pho, pwo, True)
End If
End Sub
Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int, Filter As Boolean) As Bitmap
Dim rf As Reflector
Dim bm As Bitmap
bm = rf.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
Array As Object(Original, Width, Height, Filter), _
Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
Return bm
End Sub