简体   繁体   English

仅适用于Android 4.0及以上的色带

[英]Color banding only on Android 4.0+

On emulators running Android 4.0 or 4.0.3, I am seeing horrible colour banding which I can't seem to get rid of. 在运行Android 4.0或4.0.3的模拟器上,我看到了可怕的色带,我似乎无法摆脱它。 On every other Android version I have tested, gradients look smooth. 在我测试的每个其他Android版本上,渐变看起来很流畅。

I have a SurfaceView which is configured as RGBX_8888, and the banding is not present in the rendered canvas. 我有一个配置为RGBX_8888的SurfaceView,并且渲染画布中不存在条带。 If I manually dither the image by overlaying a noise pattern at the end of rendering I can make the gradients smooth again, though obviously at a cost to performance which I'd rather avoid. 如果我通过在渲染结束时叠加噪声模式来手动抖动图像,我可以使渐变再次平滑,但显然代价是我宁愿避免的性能。

So the banding is being introduced later. 因此绑带将在稍后介绍。 I can only assume that, on 4.0+, my SurfaceView is being quantized to a lower bit-depth at some point between it being drawn and being displayed, and I can see from a screen capture that gradients are stepping 8 values at a time in each channel, suggesting a quantization to 555 (not 565). 我只能假设,在4.0+上,我的SurfaceView在被绘制和显示之间的某个点被量化为较低的位深度,我可以从屏幕截图中看到,渐变是一次步进8个值每个通道,建议量化到555(而不是565)。

I added the following to my Activity onCreate function, but it made no difference. 我将以下内容添加到我的Activity onCreate函数中,但它没有任何区别。

getWindow().setFormat(PixelFormat.RGBA_8888);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);

I also tried putting the above in onAttachedToWindow() instead, but there was still no change. 我也尝试将上面的内容放在onAttachedToWindow()上,但仍然没有变化。

(I believe that RGBA_8888 is the default window format anyway for 2.2 and above, so it's little surprise that explicitly setting that format has no effect on 4.0+.) (我相信RGBA_8888无论如何都是2.2及以上版本的默认窗口格式,因此明确设置该格式对4.0+没有影响也就不足为奇了。)

Which leaves the question, if the source is 8888 and the destination is 8888, what is introducing the quantization/banding and why does it only appear on 4.0+? 这就留下了一个问题,如果源是8888,目的地是8888,那么引入量化/条带的原因是什么,它为什么只出现在4.0+?

Very puzzling. 非常令人费解。 I wonder if anyone can shed some light? 我想知道是否有人可以放弃一些光线?

Try dis.. 试试吧..

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap gradient = BitmapFactory.decodeResource(getResources(), R.drawable.gradient, options);

findViewById(R.id.main).setBackgroundDrawable(new BitmapDrawable(gradient));

Turning on the emulator "Use Host GPU" option fixed the color problems for me, credit goes to this answer https://stackoverflow.com/a/17166234/1287459 打开模拟器“使用主机GPU”选项修复了我的颜色问题,信用转到这个答案https://stackoverflow.com/a/17166234/1287459

In my case I was using Android 4.2.2. 就我而言,我使用的是Android 4.2.2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM