Android Question bitmap background image on a ROUND CORNERS Panel, How?

Cableguy

Expert
Licensed User
Longtime User
Hi Guys,

I'm trying to set a bitmap to be the background of a Panel, no issues there, my problem is, I want to keep the round corners of the panel, I can live with loosing the border... and I would like to not use other than core or JObject to do it...

I know it must be possible... graphic gurus, please help!!
 

Cableguy

Expert
Licensed User
Longtime User
@Informatix, my question may have been placed in an unclear way... I know the panel has no round corners and that in fact, the Drawable renders the corners transparent, BUT, you are an intelligent developer, so the base questions was/is correct.

@eurojam, Thanks for the pointer, but that solution is only suitable for fixed radius corners, and that is not what I need. in its base, that would be the same as taking the paint approach suggested by informatix.

What I need to find, is how to clip/mask the bitmap to a canvas, that has round corners.
Path only has "lineto" method, I would need a "ArcTo(x,y,radius)" method
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Java has arc path methods, I just don't know java to use them... has for the Panel being in my question... From your reasoning, no control has round corners, but they are a prop in the visual designer... so at the end of the day, I could say its EREL's fault, LoL(just kidding, obviously)
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
we are discussing the wrong issue...
I stand by my question....
how to set a bitmap background to a panel, keeping the round corners with only jObject or core libs
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I know that you don't want an external library, but the ABExtDrawing library does what you want.
It contains the whole set of functions of a canvas.
So if you want to use only JavaObjects try to translate the library to what you need.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Thanks Klaus, BUT I know nothing of Java, so I don't even know where to start!
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Just B4A. Not fast, but works :D


Screenshot_2015-11-12-23-16-58.png


B4X:
    Dim Panel1 As Panel
    Dim B1,B2 As Bitmap
    Dim cv As Canvas

    B1.InitializeMutable(Activity.Width/2,Activity.Width/2)
    cv.Initialize2(B1)
    Dim Rect1 As Rect
    Rect1.Initialize(0,0,B1.Width-1,B1.Height-1)
    cv.DrawBitmap(LoadBitmap(File.DirAssets,"a_512.png"),Null,Rect1)
   
    B2.InitializeMutable(Activity.Width/2,Activity.Width/2)

    cv.Initialize2(B2)
    Dim Drawable1 As ColorDrawable
    Drawable1.Initialize(Colors.White,30)
    cv.DrawDrawable(Drawable1,Rect1)
    For r=0 To B2.Height-1
        For c=0 To B2.Width-1
            If B2.GetPixel(c,r)=Colors.White Then
                cv.DrawPoint(c,r,B1.GetPixel(c,r))
            End If
        Next
    Next

    Panel1.Initialize("")
    Activity.Color=Colors.Blue
    Activity.AddView(Panel1,(Activity.Width-B2.Width)/2,(Activity.Height-B2.Height)/2,B2.Width,B2.Height)
    Panel1.SetBackgroundImage(B2)
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
It's a working solution, but not flexible enough for my needs, nor fast...

I guess I should be more specific, and ask for the "ArcTo" java method...
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Well, this one is quite faster. What do you mean by flexibility?

B4X:
Sub AssignBitmapToPanelWithRoundBorders( P As Panel, B0 As Bitmap, radius As Int)

    Dim B1,B2 As Bitmap
    Dim cv As Canvas
    Dim Rect1 As Rect   
    
    B2.InitializeMutable(P.Width,P.Height)
    cv.Initialize2(B2)
    Dim Drawable1 As ColorDrawable
    Drawable1.Initialize(Colors.White,radius)
    Rect1.Initialize(0,0,B2.Width-1,B2.Height-1)
    cv.DrawDrawable(Drawable1,Rect1)

    B1.InitializeMutable(P.Width,P.Height)
    cv.Initialize2(B1)
    cv.DrawBitmap(B0,Null,Rect1) 
      
    For r=0 To B2.Height-1
        For c=0 To B2.Width-1
            If B2.GetPixel(c,r)=0 Then
                cv.DrawPoint(c,r,0)
            End If
        Next
    Next

    P.SetBackgroundImage(B1)   
End Sub
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
@JordiCP, I stand corrected! It's perfect! Thank you!
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
I am very impressed, how powerfull B4A - yes I knew already before - and the Users are!!

Really powerful, I agree! It only lacks the ability to allow the user to develop a B4A IDE for Android with B4A ;):eek: (joking, or who knows?)
 
Upvote 0
Top