Android颜色格式(RGB565,ARGB8888)

6
    getHolder().setFormat(PixelFormat.RGBA_888);        

    Options options = new BitmapFactory.Options();       
    options.inDither=true;                               
    options.inScaled = true; 
    options.inPreferredConfig = Bitmap.Config.ARGB_8888; 
    options.inPurgeable=true;

使用以上代码创建的位图如下:

当使用上述代码时,我得到以下结果……

  • No colour banding on my Tablet device
  • Noticeable colour banding on test mobile (Samsung Galaxy Ace)

    getHolder().setFormat(PixelFormat.RGBA_888);        
    
    Options options = new BitmapFactory.Options();       
    options.inDither=true;                               
    options.inScaled = true; 
    options.inPreferredConfig = Bitmap.Config.ARGB_565; 
    options.inPurgeable=true;
    
  • No colour banding on my tablet

  • Noticible colour banding on the Galaxy Ace
  • Same results as above

    getHolder().setFormat(PixelFormat.RGB_565);     
    
    Options options = new BitmapFactory.Options();       
    options.inDither=true;                               
    options.inScaled = true; 
    options.inPreferredConfig = Bitmap.Config.RGB_565; 
    options.inPurgeable=true;
    
  • Colour banding on my tablet

  • colour banding on the SG Ace

    getHolder().setFormat(PixelFormat.RGB_565);     
    
    Options options = new BitmapFactory.Options();       
    options.inDither=true;                               
    options.inScaled = true; 
    options.inPreferredConfig = Bitmap.Config.ARGB_8888; 
    options.inPurgeable=true;
    
  • Colour banding on my tablet

  • colour banding on the SG Ace
因此,总的来说,只有PixelFormat.xxxx部分似乎有任何区别。我的理解是这是为了设置持有者颜色格式。这将影响所有绘制的内容。(即,所有内容都将采用该格式)。
请问以下行的目的是什么?
options.inPreferredConfig = Bitmap.Config.xxxxxxx
这似乎对已绘制的位图没有任何影响。
性能至关重要,所以我可能需要更改原始png文件,使它们不具有渐变 (即,将它们绘制为RGB565 - 这是可取的,还是应该坚持使用8888?) 或者应该通过抖动来解决? (因为你可以看到,我已经启用了它,但似乎没有帮助)。
有什么想法为什么Ace上总是有条纹?这可能是硬件限制吗?
谢谢大家,这很令人困惑。
(PS我已经阅读了官方指南,在发布问题之前我总是会查看它以及查看其他相关的SO问题,但官方指南(通常情况下)并不能为我解决这个问题,并且我找不到答案通过其他问题,所以如果它已经在这里,请原谅)。
2个回答

5

默认情况下使用565格式,因为它可以更快地绘制并需要更少的处理能力。至于你的SG Ace手机,我相信一段时间之前只有某些Android版本支持8888色彩。

为了避免我的应用背景带状问题,我必须执行以下操作:

1-将背景添加到drawable文件夹

2-创建background_dithered.xml文件,并添加以下内容:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:antialias="true"
    android:dither="true"
    android:src="@drawable/background" />

3 - 在活动代码中:

@Override
public void onAttachedToWindow() {
        super.onAttachedToWindow();

        getWindow().setFormat(PixelFormat.RGBA_8888);
}       

啊,这可能解释了Ace的问题,您上面的实现是否适用于SurfaceView?(我正在使用Canvas.drawbitmap绘制背景)-谢谢 - Zippy
我不确定,因为我只是用静态png做了这个,但你可以尝试在onAttachedToWindow重写中执行set format。 - Srdjan Grubor
很确定现在默认是ARGB_8888。 - androidguy

4
请问以下代码的目的是什么? options.inPreferredConfig = Bitmap.Config.xxxxxxx 这似乎对已绘制的位图没有任何影响。
不同的Bitmap配置将具有不同的内存占用。 RGB_565是16位色格式。 ARGB_8888是32位格式。
无论您选择了哪种getHolder().setFormat();配置,或者它是如何绘制的,一个ARGB_8888位图在内存中的大小都会显着大于RGB_565格式的位图。

感谢@TylerM的回答。我理解了不同格式和内存大小等方面的知识,但我不明白上面引用的那行代码的目的是什么。您是在说,如果我有一个RGB8888图像,并将其加载到inPreferredConfig设置为RGB565,那么它会在内存中变小吗?如果是这样,为什么当我将持有者设置为8888时,它仍然以无条纹(即32位格式)的方式显示?抱歉,如果这没有道理,但我不明白......谢谢 :-/ - Zippy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接