在不同背景上使用时如何去除图像周围的白色边框?
2 回答
OK, I have seen the image and you want the ImageView to be of the same shape as your image because you don't want to see the white border around your image.
Well,in short, I don't think that is possible AFAIK. ImageView is a rectangular view which asks for height,width.
However, rather than try to do the impossible, I would suggest you to use alpha-masking( subset of alpha blending, google them to know more).
A little theory: depending on the alpha bits for each pixel in your Bitmap (the translucency bits), the extent of blending of that pixel with over-written pixel is determined. Considering extremes, if alpha is 255, overwriting pixel is used instead of the over-written one (fully opaque, in regular terms); if alpha is 0, overwriting pixel is just ignored (transparent). For other alphas in between: there is blending.
In your case you would have to make the alpha of the border zero, to achieve complete blend. Outlining the steps:.
- The drawable to be used can't be a JPEG( JPEG doesn't store alpha values per pixel). Go for PNGs
2.You will need to create and keep your bitmap drawable in that way beforehand(use google for alpha blending PNGs) such that the borders have zero alpha value ( use softwares like Paint.NET for ex).
- If images are being created dynamically, you would need to use a blending equation ( for details read materials by Porter and Duff).
For ex, this is PNG image with transparent pixels having alpha 0 other than the alphabet itself
.
Above is the alpha blended PNG on colored background of an Activity. I hope this is what you really want to achieve, and my answer is actually useful .
如果您尝试将其用作主屏幕背景,然后将其布局权重和高度设置为“fill_parent”,则背景可以是您希望它作为参考的任何图像,就像您所做的 SRC 调用一样。这将使图像仅填满屏幕,并允许您使用 SCR 命令在屏幕上写入。如果您给我们更多您所做的事情,我们可以提供更多帮助。