ImageView with Transparency

klaus

Expert
Licensed User
Longtime User
I would like to use ImageView views to display several layers.
- Setting the ImageView.Color to a 'transparent' color Colors.ARGB(0,255,255,255)
- Drawing onto the ImageViews and playing with the ImageView.Visible parameter allows to display or hide the layers.

All this works fine.

Then I would 'erase' a part of the ImageView, setting this part to transparent. How can this be done.

For the moment I can set the whole ImageView to transparent but not just a part of it, and all the other drawings must be drawn again.
Drawing a rectangle with the transparent color has no effect because it draws transparent onto the existing image, so no effect. I would set the bitmap's pixels to transparent.

I am porting my Sudoku program from B4PPC to B4Android and want to display the small numbers on one layer and cell background colors on another layer. To remove the small numbers in one cell I would set only this surface to transparent, similar with a cell background color. For the moment I must set the whole surface to transparent and draw all the other numbers again.

Attached a small test program, I want to set only the red square to transparent.

Best regards.
 

Attachments

  • TestLayers.zip
    6.2 KB · Views: 473

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

klaus

Expert
Licensed User
Longtime User
Unfortunately the principle of the Smiley program doesn't do what I want to do.
In my case the original bitmap is transparent, even when I draw a part of this original bitmap onto the current bitmap nothing happens due to the blending of the transparency.:(
I need to replace a part of the current bitmap's pixels by those of the same part of the original bitmap.

I saw in the Android documentation that there do exist the functions GetPixel, GetPixels, SetPixel and SetPixels for Bitmaps.
Currently, only GetPixel is implemented.

Could you please add the 3 other functions in the new release. I'm shure that this would give a great flexibility in graphics. Playing with layers would become quite easy and powerful.

Thank you in advance and Best regards.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Drawing a black rectangle doesn't do it.

I'm not shure if my explanations were clear enough.

Attached a new version of the test program.
- The Activity color is black.
- A transparent ImageView BG, covering the upper part of the screen, is on top of the activity with two colored background squares.
- A second transparent ImageView NB is on top of the previous one with 2 numbers.

- NumberON / OFF shows or hides the numbers
- Backgrnd ON / OFF shows or hides the backgrounds
- Set NB 1 sets number 1
- Clear NB 1 should clear number 1 (set to transparent) but doesn't
- Set BG 1 sets the red square
- Clear BG 1 should erase BG 1 (set to transparent) but doesn't
- Set NB 2 sets number 2
- Clear Nb 2 should clear number 2 (set to transparent) but doesn't
- Set BG 2 sets the green square
- Clear BG 2 should erase BG 2 (set to transparent) but doesn't
- T NB sets all numbers transparent
- T BG sets all background to transparent

What I want to do is to set either NB1, NB2, BG1 or BG to transparent.
Clicking onto Clear NB 1 sets Square around the number to black, acording to your proposal, but it covers the red rectangle and it is not transparent. The red rectangle should still be visible.
Clicking onto T NB for transparent number sets the whole ImageView to transparent, but it removes both numbers, so I need to redraw the number I didn't want to erase.

But I'm shure that with Bitmap.GetPixels(x,y,w,h) on the original bitmap and Bitmap.SetPixels(x,y,w,h) to erase would do it. Because the SetPixels function will replace the ImageView pixels and not draw onto it.

Best regards.
 

Attachments

  • TestLayers.zip
    6.4 KB · Views: 348
  • TestLayers.jpg
    TestLayers.jpg
    23.9 KB · Views: 748
Upvote 0

klaus

Expert
Licensed User
Longtime User
That's very good news, setting the pixels to transparent when drawing with Colors.Transparent was my 'secret' wish.

Best regards.
 
Last edited:
Upvote 0
Top