Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Dim B As Bitmap = LoadBitmap(file.DirAssets,"test.png")
Dim Size As Int = GetBitmapSizeinBytes(B)
Dim Percent10k As Float = Sqrt(10240/Size) '10k
Dim Percent100k As Float = Sqrt(100240/Size) '100k
If Percent10k<1 Then B=CreateScaledBitmap(B,B.Width*Percent10k,B.Height*Percent10k)
End Sub
Sub GetBitmapSizeinBytes (myBitmap As Bitmap) As Int
Dim ByteCount As Int
Dim jo As JavaObject = myBitmap
Dim joSDK As JavaObject
joSDK.InitializeStatic("android.os.Build.VERSION")
If joSDK.GetField("SDK_INT") >= 19 Then 'kitkat
ByteCount = jo.RunMethod("getAllocationByteCount", Null)
else if joSDK.GetField("SDK_INT") >= 12 Then 'Android 3.1 Honeycomb
ByteCount = jo.RunMethod("getByteCount", Null)
Else 'earlier Android versions
ByteCount = jo.RunMethod("getRowBytes", Null) * myBitmap.Height
'the code below could replace the formula above for earlier Android versions
'ByteCount = myBitmap.Width * myBitmap.Height * 4
End If
Return ByteCount
End Sub
Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int) As Bitmap
Dim r As Reflector
Dim Filter As Boolean =False
Dim b As Bitmap
b = r.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 b
End Sub