Alpha Channels / Masking

You must Login before you can answer or comment on any questions.

Hi all,

I'm trying to simply place a static image on the screen. It presently has a black background which I would like to make transparent so you see just the graphic itself but I can't get 'color; '#0000' or '#00000000' to do the job.

I need this to work on both Android and iOS so I am not keen to use the iOS only APIs.

I'm guessing I'm doing something wrong. I am loading an image as a background image into either a view or imageView (neither work).

Should I be using blobs? Is there any documentation on these please as I can't find anything terribly helpful.

Can someone tell me what I need to do please?

— asked 12 months ago by Robin Williams
1 Comment
  • Just to add - I've been using .jpg & .png images - does the file format matter?

    — commented 12 months ago by Robin Williams

1 Answer

Accepted Answer

I'm not sure what you're doing in your code to add an alpha channel to the image. You can't do that -- either the image has an alpha channel or it doesn't. JPEG files do not have alpha channels. You have to use a PNG.

This isn't like the days of GIF where you would designate one color as transparent. Each pixel in a PNG has R, G, B, and A components.

If you display a PNG with an alpha channel in an ImageView, the parent view's background will show through the transparent parts of the image they way you want.

You should load the image in question into an image editor and remove the black pixels, leaving transparency behind.

— answered 12 months ago by Jason Priebe
answer permalink
1 Comment
  • That's really helpful, thank you. I had eventually got a png to work but i didn't know why! If you look in the documentation for 'color' it mentions that you can add an alpha / mask at the beginning of a color declaration to control the opacity of that color, that's why i had gone down that avenue! This is so much easier though! Lol. Thanks again!

    — commented 12 months ago by Robin Williams

Your Answer

Think you can help? Login to answer this question!