问题描述
在运行Android 4.0或4.0.3,我看到可怕的色带的模拟器,我似乎无法摆脱。在所有其他Android版本我已经测试过,梯度看起来光滑。
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. On every other Android version I have tested, gradients look smooth.
予有被配置为RGBX_8888一个SurfaceView,并且条带是不present渲染画布。如果我通过叠加的渲染,我可以使梯度再次顺利结束的噪声曲线,但显然在成本,性能,我宁愿避免手动抖动的图像。
I have a SurfaceView which is configured as RGBX_8888, and the banding is not present in the rendered canvas. 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.
因此,绑扎正在晚些时候推出。我只能认为,对4.0以上版本,显示我的SurfaceView被量化到一个较低的比特深度,它正在起草和之间的某一点,我可以从屏幕捕获的梯度正在加紧8个值在一时间看每个通道,这表明量化至555(未565)。
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).
我增加了以下到我的活动的onCreate功能,但它并没有区别。
I added the following to my Activity onCreate function, but it made no difference.
getWindow().setFormat(PixelFormat.RGBA_8888);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
我也试过把上述onAttachedToWindow()来代替,但仍然没有改变。
I also tried putting the above in onAttachedToWindow() instead, but there was still no change.
(我相信RGBA_8888是默认窗口格式,无论如何,2.2及以上,所以它的小惊喜,明确设置该格式对4.0 +没有任何影响。)
(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+.)
这留下一个问题,如果源是8888和目标是8888,什么是引入量化/带和它为什么只出现在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+?
很令人费解。我不知道是否有人能提供一些线索?
Very puzzling. I wonder if anyone can shed some light?
推荐答案
尝试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));
这篇关于色带仅在Android 4.0+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!