-1

在不同背景上使用时如何去除图像周围的白色边框?

在此处输入图像描述

http://groups.google.com/group/android-developers/browse_thread/thread/f4ef24e03431bbe4/ce7f19488fd0388a?lnk=gst&q=Crop+Image+View+that+fits+to+the+image#ce7f19488fd0388a

4

2 回答 2

0

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:.

  1. 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).

  2. 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
    . original PNG with alpha blending

aplha blended PNG on colored background

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 .

于 2012-04-10T20:59:30.840 回答
0

如果您尝试将其用作主屏幕背景,然后将其布局权重和高度设置为“fill_parent”,则背景可以是您希望它作为参考的任何图像,就像您所做的 SRC 调用一样。这将使图像仅填满屏幕,并允许您使用 SCR 命令在屏幕上写入。如果您给我们更多您所做的事情,我们可以提供更多帮助。

于 2012-04-10T19:48:33.197 回答