不同设备上的平滑渐变
在我的应用程序中,我有可绘制的渐变,我将其用作背景,我不希望它看起来尽可能平滑。经过谷歌搜索并亲自尝试后,我得出了以下结论。在nexus 1上,如果您仅调用setDither(true),您的渐变仍然是条带,因此您必须像这样设置PixelFormat Window.setFormat(PixelFormat.RGBA_8888)。但另一方面,G1 不支持 RGBA_8888,因此调用它会使渐变比以前更难看,因此 Window.setFormat(PixelFormat.RGBA_8888) 在不支持它的设备上无法正常工作。
在运行我的应用程序的所有设备上平滑渐变的正确方法是什么?
PS:我找到了一些相关主题
In my app i have gradient as drawable which i am using as background and i wan't it to make it look as smooth as possible. After googling and trying by myself i came up with the following. On nexus one if you call only setDither(true) your gradient is still banding so you have to set PixelFormat like this Window.setFormat(PixelFormat.RGBA_8888). But on the other side G1 does not support RGBA_8888 so calling it make the gradient even uglier than before so Window.setFormat(PixelFormat.RGBA_8888) will not work well on devices that don't support it.
What is the correct way smooth my gradient on all devices on which my app will run.
PS: i found some related topics
How to draw a smooth/dithered gradient on a canvas in Android
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 Photoshop(或 Gimp 或 Paint.NET 等)中打开图像并添加少量噪点。然后您无需在代码中执行任何操作。
Open your image in Photoshop (or Gimp or Paint.NET or whatever) and add a small quantity of noise. Then you don't have to do anything in code.
您可以使用自定义形状(将其放入 /drawable/gradient.xml 或类似的东西中):
这样它将由操作系统绘制,并且应该非常平滑。
You can use a custom shape (put it in /drawable/gradient.xml or something like that):
This way it will be painted by the os and it should be perfectly smooth.
加载图像时,如果您将图像直接绘制到屏幕上而不进行其他修改,请将 PixelFormat 设置为 RGB_565 并将 setDither 设置为 true。
显示器通常不是 24 位,但通常应该足够好,至少在各处都相当一致。
如果您不需要 Alpha 并且不会修改图像数据,则不需要使用 8888。它将在 99% 的移动显示器上显示为 16 位颜色,而不是 24 位颜色,因为面板支持 24 位颜色。
N1 总是会遇到问题,因为他们用于面板的矩阵具有双倍的绿色分辨率。
When loading your image, set the pixelFormat to RGB_565 and setDither to true, if you are drawing it straight to the screen with no other modification.
The displays typically aren't 24bit, that should typically do it good enough, at least pretty consistently all around.
You don't need to use 8888 if you don't need the alpha and won't be modifying the image data. It will displayed on 99% of mobile displays as 16bit color and not 24bit, since that is what the panels support.
N1 will always have issues close up because the matrix they use for the panel has double the green resolution.
如果抖动和 RGBA_888 设置在某些手机上不起作用,解决方案可以是将元素
layerType
设置为software
,以禁用硬件加速这解决了我的问题三星 S5 手机。
If the dither and RGBA_888 setting don't help on some phones, the solution can be to set the element
layerType
tosoftware
, to disable the hardware accelerationThis fixed my problem on a Samsung S5 phone.