Sub DrawBitmapRotated(canvas1 As Canvas, Bitmap1 As Bitmap, SrcRect As Rect, DestRect As Rect, Degrees As Float)
Dim no As NativeObject = canvas1
no.RunMethod("rotate:::", Array(Degrees, DestRect.CenterX, DestRect.CenterY))
DrawBitmap(canvas1, Bitmap1, SrcRect, DestRect)
no.RunMethod("rotate:::", Array(-Degrees, DestRect.CenterX, DestRect.CenterY))
End Sub
Sub DrawBitmap(canvas1 As Canvas, Bitmap1 As Bitmap, SrcRect As Rect, DestRect As Rect)
If SrcRect = Null Then
Dim SrcRect As Rect
SrcRect.Initialize(0, 0, Bitmap1.Width, Bitmap1.Height)
End If
Dim p1 As Path
p1.InitializeRect(DestRect, 0)
canvas1.ClipPath(p1)
Dim sx, sy As Float
sx = (DestRect.Right - DestRect.Left) / (SrcRect.Right - SrcRect.Left)
sy = (DestRect.Bottom - DestRect.Top) / (SrcRect.Bottom - SrcRect.Top)
Dim x, y, width, height As Int
x = DestRect.Left - sx * SrcRect.Left
y = DestRect.Top - sy * SrcRect.Top
width = Bitmap1.Width * sx
height = Bitmap1.Height * sy
Dim d2 As Rect
d2.Initialize(x, y, x + width, y + height)
canvas1.DrawBitmap(Bitmap1, d2)
canvas1.RemoveClip
End Sub
It is one of the purposes. However when the native APIs are too different there is always a tension between building a thick abstraction above the native APIs vs. a thin abstraction. There is a price for thick abstractions.isn't it the purpose of B4x to stick to the same common methods/syntax in all tools to make it easier for us switching between B4A/B4i/B4J?
Not offended. iOS and Android are very different platforms. As someone who is deeply familiar with both platforms I'm very happy with the amount of code that can be reused between the platforms. More importantly, B4i follows the same concepts of B4A and B4J which means that it should not be too difficult for a developer to switch from one platform to another.don't feel offended but i'm getting into one surprise after the other while expecting it to be more simular.
Sub RotateImage(original As Bitmap, degree As Float) As Bitmap
Dim matrix As JavaObject
matrix.InitializeNewInstance("android.graphics.Matrix", Null)
matrix.RunMethod("postRotate", Array(degree))
Dim bmp As JavaObject
bmp.InitializeStatic("android.graphics.Bitmap")
Dim NewImage As Bitmap = bmp.RunMethod("createBitmap", Array(original, 0, 0, original.Width, original.Height, _
matrix, True))
Return NewImage
End Sub