Sub GetOrientation As Int
' 0 = portrait
' 1 = landscape left
' 3 = landscape right
Dim R As Reflector
R.Target = R.GetContext
R.Target = R.RunMethod2("getSystemService", "window", "java.lang.String")
R.Target = R.RunMethod("getDefaultDisplay")
Return R.RunMethod("getOrientation")
End Sub
Sub Camera1_PictureTaken (Data() As Byte)
Dim In As InputStream
Dim Out As OutputStream
Dim drect As Rect
' make a bitmap of the data stream from the camera
In.InitializeFromBytesArray(Data, 0, Data.Length)
Dim bmp, bmp2 As Bitmap
bmp.Initialize2(In)
bmp2.Initialize3(bmp)
In.Close
' check orientation and height/width ratio of the picture
If bmp.Width > bmp.Height AND Orientation = 0 Then
' portrait oriention, but landscape photo
RESU = RotateBitmap90(bmp) 'RESU met resultaat
Out = File.OpenOutput(Imagefolder, bestand, False)
RESU.WriteToStream(Out, 100, "JPEG")
Else
camera1.SavePictureToFile(Data, Imagefolder, bestand)
End If
camera1.StartPreviewEnd
Sub
Sub RotateBitmap90(SBMP As Bitmap) As Bitmap
Dim bb As Bitmap
Dim angle As Int : angle = 90
'original size
Dim pwo As Int
Dim pho As Int
'resized to ...
Dim sqp As Int
Dim Recto As Rect
Dim c As Canvas
pwo = SBMP.Width
pho = SBMP.Height
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 (SBMP, sqp, sqp, True)
End If
bb.InitializeMutable(sqp,sqp)
Recto.Initialize(0, 0,sqp,sqp)
'ROTATE masterPic into bb
c.Initialize2(bb)
c.DrawBitmapRotated(SBMP, Null, Recto, angle) 'Draw the new image
SBMP.Initialize3(bb)
'RESIZE back inverse, if pic was not square
If pwo <> pho Then
SBMP = CreateScaledBitmap (bb, pho, pwo, True)
End If
Return SBMP
End Sub
Sub CreateScaledBitmap(Original As Bitmap, Widths As Int, Heights As Int, Filters As Boolean) As Bitmap
Dim R As Reflector
Dim b As Bitmap
b = R.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
Array As Object(Original, Widths, Heights, Filters), _
Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
Return b
End Sub