ImageView 下方带有完全透明背景的 png 的阴影伪影
我正在开发 Gingerbread (2.3.3) 设备。我有一个 ImageView,其中包含一个箭头图,并且有一个完全透明的背景,我需要在某些背景上绘制它。问题是 ImageView 的边界框下方有一个“阴影”伪像。
如果仔细观察下图,您会看到我正在谈论的工件: 1
两个前景图像背景图像具有 Alpha 通道,因此被解码为 ARGB8888(我通过手动将其资源解码为位图来仔细检查这一点,打印出显示 ARGB8888 的位图配置,然后将它们分配给各自的视图)。在调用 setContentView() 之前,我还将 Activitiy 的窗口配置为 PixelFormat.RGBA_8888。
请不要向我推荐建议将位图解码为 ARGB8888 和/或将窗口设置为 RGBA_8888 的线程,因为我尝试了这两种解决方案,但这没有帮助。
有什么想法可以解决这个问题吗?
编辑:
这是设置窗口像素格式和可绘制对象的函数(直接从 onCreate() 调用):
public void testTransparency() { getWindow().setFormat(PixelFormat.RGBA_8888); setContentView(R.layout.transparency_test); LinearLayout ll = (LinearLayout)findViewById(R.id.ll); 位图 bgBmp = BitmapFactory.decodeResource(getResources(), R.raw.bg); Log.d(TAG,"BG BMP 配置:" + bgBmp.getConfig()); ll.setBackgroundDrawable(new BitmapDrawable(bgBmp)); ImageView iv = (ImageView)findViewById(R.id.iv); iv.setBackgroundDrawable(null); 位图 arrowBmp = BitmapFactory.decodeResource(getResources(), R.raw.big_arrow); Log.d(TAG,"箭头 BMP 配置:" + arrowBmp.getConfig()); iv.setImageBitmap(arrowBmp); }
这是我的测试使用的(非常简单)布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView android:id="@+id/iv"
android:layout_width="72dp"
android:layout_height="120dp"
/></LinearLayout>
“bg”资源可以在 2
找到 “big_arrow”资源可以在“http://i.imgur.com/3V6QU.png”找到
编辑2:
我发现我无法在模拟器上重现该问题,也无法在我的 N1 (2.3.4) 或 XOOM (3.2.1) 上重现该问题。从这里继续有 2 个选项:
1.问题是特定于设备的(我正在开发基于Android的设备)
2. 在相互叠加渲染透明 PNG 时,2.3.4 和 32BPP 帧缓冲区存在一个特定问题。
谢谢。
I'm working on a Gingerbread (2.3.3) device. I have an ImageView which contains an arrow figure and have a fully transparent background which I need to draw on some background. The problem is that there's a "shading" artifact beneath the ImageView's bounding box.
If you look closely on the following image, you'll see the artifact i'm talking about: 1
Both the foreground image and the background image have alpha channels and therefore are decoded as ARGB8888 (I double checked this by manually decoding their resources into a bitmap, print out the bitmap configuration which showed ARGB8888, and then assigning them to their respective views). I also configured the Activitiy's window to be PixelFormat.RGBA_8888 before the call to setContentView().
Please don't refer me to threads that suggest decoding the bitmap as ARGB8888 and/or set the window to be RGBA_8888, since I tried both solutions, which didn't help.
Any ideas how can I fix this issue?
EDIT:
Here's the function which sets the Window pixel format and drawables (called directly from onCreate()):
public void testTransparency() { getWindow().setFormat(PixelFormat.RGBA_8888); setContentView(R.layout.transparency_test); LinearLayout ll = (LinearLayout)findViewById(R.id.ll); Bitmap bgBmp = BitmapFactory.decodeResource(getResources(), R.raw.bg); Log.d(TAG,"BG BMP Config: " + bgBmp.getConfig()); ll.setBackgroundDrawable(new BitmapDrawable(bgBmp)); ImageView iv = (ImageView)findViewById(R.id.iv); iv.setBackgroundDrawable(null); Bitmap arrowBmp = BitmapFactory.decodeResource(getResources(), R.raw.big_arrow); Log.d(TAG,"Arrow BMP Config: " + arrowBmp.getConfig()); iv.setImageBitmap(arrowBmp); }
And here's the (very simple) layout my test is using:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView android:id="@+id/iv"
android:layout_width="72dp"
android:layout_height="120dp"
/></LinearLayout>
The 'bg' resource can be found at 2
The 'big_arrow' resource can be found at "http://i.imgur.com/3V6QU.png"
EDIT 2:
I found out I can't reproduce the problem on the emulator, nor on my N1 (2.3.4) or XOOM (3.2.1). There are 2 options continuing from here:
1. The problem is device specific (Android based appliance i'm working on)
2. There's a specific problem with 2.3.4 and 32BPP framebuffer while rendering transparent PNGs on top of each other.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简单的设置
解决了我在 Android 2.3.5 的 HTC Desire HD 上使用 ImageButton 的问题,其中我的按钮图像的高度低于默认背景。经验观察;在运行 Android 4.1.2 的 Galaxy Note 1 上未显示该工件
Simply setting
solved my issue with an ImageButton on a HTC Desire HD with Android 2.3.5 where my button image has less height than the default background. Empiric observation; artifact did not show on a Galaxy Note 1 with Android 4.1.2
发现了该错误,确实这是一个特定于平台的错误。
我发现当我删除 SKIA 混合位块传输部分中的霓虹灯优化(在 SkBlitRow_D32.cpp - SkBlitRow::Proc32 SkBlitRow::Factory32(unsigned flags))时,着色伪像消失了。
对于任何想要调试此类错误的人来说,这是一个有用的提示:
您始终可以将视图层次结构绘制到位图(请参阅:Android例如,在绘制之前获取视图的位图?),然后使用 Bitmap.compress 方法将位图导出到 PNG 文件。通过这种方式,您可以获得带有 Alpha 通道的视图层次结构快照(它不会出现在 DDMS 屏幕截图中,因为它是在合成后生成的)。我发现阴影区域内的 alpha 值是“1”而不是“0”,从而创建了伪影。
Found the bug and indeed it was a platform specific bug.
I found out when I remove the neon optimizations in the blended blitting portion of SKIA (in SkBlitRow_D32.cpp - SkBlitRow::Proc32 SkBlitRow::Factory32(unsigned flags)), the shading artifact disappears.
A useful tip for anyone who want to debug this sort of bugs:
You can always draw your view hierarchy to a bitmap (See: Android get a bitmap of a view before drawing? for example) and then use Bitmap.compress method to export the bitmap to a PNG file. This way you can obtain your view hierarchy snapshot with its alpha channel (Which doesn't appear in A DDMS screenshot since it's generated after composition). I found out this way that the alpha value within the shaded area is '1' instead of '0', creating the artifact.