Android Code Snippet Draw round bitmap

Erel

Administrator
Staff member
Licensed User
Sub Name: DrawRoundBitmap

Description: This code uses Path object to draw a round bitmap at the center of a transparent mutable bitmap.

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim cvs As Canvas = CreateBitmap
   DrawRoundBitmap(cvs, LoadBitmap(File.DirAssets, "1.jpg"))
   Activity.SetBackgroundImage(cvs.Bitmap)
End Sub

Sub CreateBitmap As Canvas
   Dim bmp As Bitmap
   bmp.InitializeMutable(200dip, 200dip)
   Dim cvs As Canvas
   cvs.Initialize2(bmp)
   Dim r As Rect
   r.Initialize(0, 0, bmp.Width, bmp.Height)
   cvs.DrawRect(r, Colors.Transparent, True, 0)
   Dim p As Path
   p.Initialize(0, 0)
   Dim jo As JavaObject = p
   Dim x = 100dip, y = 100dip, radius = 100dip As Float
   jo.RunMethod("addCircle", Array As Object(x, y, radius, "CW"))
   cvs.ClipPath(p)
   Return cvs
End Sub

Sub DrawRoundBitmap (cvs As Canvas, bmp As Bitmap)
   Dim r As Rect
   r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
   cvs.DrawBitmap(bmp, Null, r)
End Sub


Dependencies: JavaObject

Tags: round bitmap, ClipPath
 
Last edited:

LucaMs

Expert
Licensed User
I know that you do not need the Likes, but I love the Snippets.

My "like" has the value of "thank you"
 

deyvitavara

New Member
Licensed User
Sub Name: DrawRoundBitmap

Description: This code uses Path object to draw a round bitmap at the center of a transparent mutable bitmap.

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim cvs As Canvas = CreateBitmap
   DrawRoundBitmap(cvs, LoadBitmap(File.DirAssets, "1.jpg"))
   Activity.SetBackgroundImage(cvs.Bitmap)
End Sub

Sub CreateBitmap As Canvas
   Dim bmp As Bitmap
   bmp.InitializeMutable(200dip, 200dip)
   Dim cvs As Canvas
   cvs.Initialize2(bmp)
   Dim r As Rect
   r.Initialize(0, 0, bmp.Width, bmp.Height)
   cvs.DrawRect(r, Colors.Transparent, True, 0)
   Dim p As Path
   p.Initialize(0, 0)
   Dim jo As JavaObject = p
   Dim x = 100dip, y = 100dip, radius = 100dip As Float
   jo.RunMethod("addCircle", Array As Object(x, y, radius, "CW"))
   cvs.ClipPath(p)
   Return cvs
End Sub

Sub DrawRoundBitmap (cvs As Canvas, bmp As Bitmap)
   Dim r As Rect
   r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
   cvs.DrawBitmap(bmp, Null, r)
End Sub


Dependencies: JavaObject

Tags: round bitmap, ClipPath
Erel,

How could I do if I want to add color and size to the edge?

Thank you!
 
Top