Android Code Snippet Draw round bitmap

Discussion in 'Code Snippets' started by Erel, May 21, 2014.

  1. Erel

    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.

    Code:
    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(
    200dip200dip)
       
    Dim cvs As Canvas
       cvs.Initialize2(bmp)
       
    Dim r As Rect
       r.Initialize(
    00, bmp.Width, bmp.Height)
       cvs.DrawRect(r, 
    Colors.Transparent, True0)
       
    Dim p As Path
       p.Initialize(
    00)
       
    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(
    00, cvs.Bitmap.Width, cvs.Bitmap.Height)
       cvs.DrawBitmap(bmp, 
    Null, r)
    End Sub
    [​IMG]

    Dependencies: JavaObject

    Tags: round bitmap, ClipPath
     
    Last edited: Sep 4, 2016
    Vahid.m, yiankos1, Beja and 18 others like this.
  2. LucaMs

    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"
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Actually I do like the Likes :)
     
    Beja, eps and LucaMs like this.
  4. anOparator

    anOparator Active Member Licensed User

    I thought the round/oval button was a great option , this eclipses that :cool:
     
  5. deyvitavara

    deyvitavara New Member Licensed User

    Erel,

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

    Thank you!
     
  6. asales

    asales Well-Known Member Licensed User

  7. deyvitavara

    deyvitavara New Member Licensed User

    konradwalsh likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice