Android Question Set semi transparency of a panel outside its contained image

Matteo Granatiero

Active Member
Licensed User
For the semi-transparency of the panel use:
B4X:
Dim cd As ColorDrawable
    cd.Initialize ( Colors.ARGB( 100, 0, 0, 0) , 5dip )
    Panel1.Background = cd

The problem is: if I load an image in the panel (which is smaller than the panel panel because I set Gravity.Center, how do I set the rest of the panel with semi-transparency without "coloring" the inside of the image?
I attach image to make the idea
 

Attachments

  • b4.png
    b4.png
    14.4 KB · Views: 513

Semen Matusovskiy

Well-Known Member
Licensed User
A sample without libraries

1) Declare and load a bitmap
B4X:
    Dim Panel1 As Panel
    Dim ImageView1 As ImageView
    Dim bitmap As Bitmap = LoadBitmap (File.DirAssets, "MyPicture.jpg")

2) Place Panel1
B4X:
    Activity.Color = Colors.White   
    Panel1.Initialize ("")
    Activity.AddView (Panel1, 10%x, 10%y, 80%x, 80%y)   
    Dim cd As ColorDrawable
    cd.Initialize (Colors.ARGB (100, 0, 0, 0), 5dip)
    Panel1.Background = cd

3) For example, you want padding ("borders") minimum 10dip from each side
Let's calculate scale factor:
B4X:
    Dim scale As Double = Min ((Panel1.Width - 2 * 10dip) / bitmap.Width, (Panel1.Height - 2 * 10dip) / bitmap.Height)

4) Last step
B4X:
    ImageView1.Initialize ("")
    ImageView1.Gravity = Gravity.FILL
    ImageView1.Bitmap = bitmap
    Panel1.AddView (ImageView1, (Panel1.Width - scale * bitmap.Width) / 2, (Panel1.Height - scale * bitmap.Height) / 2, scale * bitmap.Width, scale * bitmap.Height)
 
Upvote 0

Matteo Granatiero

Active Member
Licensed User
give me this error

B4X:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
 
Upvote 0

Matteo Granatiero

Active Member
Licensed User
I want the inside of this image to be transparent and not to have the color of the panel:(
 

Attachments

  • Screenshot_20180926-194646.png
    Screenshot_20180926-194646.png
    125.3 KB · Views: 334
  • 1.png
    1.png
    92.9 KB · Views: 384
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I want the inside of this image to be transparent and not to have the color of the panel:(
This is totally different from the goal you posted in #1!!!
In #1 you was writing about an Image in thr middle of a panel. So single word about a t-shirt and it´s outline.

Thank you for wasting everyones time. Especially @Semen Matusovskiy
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
I deleted a comment because you deleted your zip-file.
About t-shirt. If you want to change color for t-shirt (let's say yellow), you need to edit png in graphic editor - this is the most simple solution
 
Upvote 0

Matteo Granatiero

Active Member
Licensed User
This is totally different from the goal you posted in #1!!!
In #1 you was writing about an Image in thr middle of a panel. So single word about a t-shirt and it´s outline.

Thank you for wasting everyones time. Especially @Semen Matusovskiy

read well what I scirtto in # 1:
how do I set the rest of the panel with semi-transparency without "coloring" the inside of the image?
 
Upvote 0

Matteo Granatiero

Active Member
Licensed User
I deleted a comment because you deleted your zip-file.
About t-shirt. If you want to change color for t-shirt (let's say yellow), you need to edit png in graphic editor - this is the most simple solution

I want the inside of the image to be transparent! The 1.png image is it but inside the panel you can see the color of the panel. The INITIAL question was just this, how not to visualize the color of the panel inside the embankment
Example on photoshop :
 

Attachments

  • Screenshot_20180926-194646.png
    Screenshot_20180926-194646.png
    138.4 KB · Views: 399
  • 1.png
    1.png
    92.9 KB · Views: 363
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Which color do you want to see ?

Guess, you want to see like in attached png. Correct ? If so, you must prepare png : around t-shirt - transparent color, inside t-shirt - solid colors.
 

Attachments

  • 1.png
    1.png
    33.2 KB · Views: 289
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Sorry, I don't understand
At first, we did both variant. What's wrong with first ?
The background of activity is light-color.
Panel color is semi-transparent black color (looks like dark red)
Inside and outside t-shirt there is the same color - semi-transparent black.


001.png



The second variant - t-shirt is colored. Which third variant can be ?



002.png
 
Upvote 0

Matteo Granatiero

Active Member
Licensed User
I want the inside of the shirt to be TRANSPARENT (in this case see the red) But this does not mean that I have to color the inside of the shirt red. I got it?
 

Attachments

  • 001.png
    001.png
    77.6 KB · Views: 305
Upvote 0
Top