iOS Question Create BMP, help porting this simple code in B4i

marcick

Well-Known Member
Licensed User
Longtime User
This code works in B4x and create a bmp that is a simple circle with a number centered inside.
I have non skill to make it working in B4i ......

B4X:
Sub CreateNumberedBitmap(Number As Int) As Bitmap
    Dim size As Int = 64dip
    Dim bmp As Bitmap
    bmp.InitializeMutable(size, size)
    Dim cvs As Canvas
    cvs.Initialize2(bmp)
    cvs.DrawColor(Colors.Transparent)
    ' blue circle
    cvs.DrawCircle(size / 2, size / 2, size / 2 - 2dip, Colors.blue, True, 0)
    ' white border
    cvs.DrawCircle(size / 2, size / 2, size / 2 - 2dip, Colors.white, False, 5dip)
    ' white text centered
    Dim text As String = Number
    Dim fontSize As Float = 28
    Dim font As Typeface = Typeface.DEFAULT_BOLD
    Dim textWidth As Float = cvs.MeasureStringWidth(text, font, fontSize)
    Dim textHeight As Float = cvs.MeasureStringHeight(text, font, fontSize)
    Dim x As Float = (size - textWidth) / 2
    Dim y As Float = (size + textHeight) / 2
    cvs.DrawText(text, x, y, font, fontSize, Colors.White,"LEFT")
    Return bmp
End Sub
 

marcick

Well-Known Member
Licensed User
Longtime User
I solved like this.

B4X:
Sub CreateNumberedBitmap(Number As Int) As B4XBitmap
    Dim size As Int = 32 
    Dim c As B4XCanvas
    Dim xview As B4XView = xui.CreatePanel("")
    xview.SetLayoutAnimated(0, 0, 0, size, size)
    c.Initialize(xview)
    Dim fillColor As Int = Colors.Blue
    Dim strokeColor As Int = Colors.White
    c.DrawCircle(size / 2, size / 2, size / 2 - 3dip, fillColor, True, 0)
    c.DrawCircle(size / 2, size / 2, size / 2 - 3dip, strokeColor, False, 2dip)
    Dim fontSize As Float = 14
    Dim MyFont As Font = Font.CreateNewBold(fontSize)
    Dim yOffset As Float = fontSize / 3
    c.DrawText(Number, size / 2, size / 2 + yOffset, MyFont, Colors.White, "CENTER")
    Return c.CreateBitmap
End Sub
 
Upvote 0
Top