Android 颜色格式(RGB565、ARGB8888)

标签 android bitmap rgb bitmapfactory argb

    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;

(使用上述选项创建的位图)

当使用上面的代码时,我得到以下结果.........

  • 我的平板电脑设备上没有色带
  • 测试手机 (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;
    
  • 我的平板电脑上没有色带

  • Galaxy Ace 上有明显的色带
  • 结果同上

    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;
    
  • 我的平板电脑上出现色带

  • 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;
    
  • 我的平板电脑上出现色带

  • SG Ace 上的色带

因此,总而言之,似乎只有 PixelFormat.xxxx 部分有所不同。我的理解是这是设置holder的颜色格式。这将影响绘制的所有内容。 (即,一切都将采用该格式)。

有人可以解释下一行的目的吗?

options.inPreferredConfig = Bitmap.Config.xxxxxxx

这似乎对已经绘制的位图没有任何影响。

性能是最重要的,所以我可能不得不更改我的原始 png 文件,使它们没有渐变,(即,将它们绘制为 RGB565 - 这是可取的还是我应该坚持使用 8888?)或者应该抖动排序出去? (因为如您所见,我启用了它,但它似乎没有帮助)。

知道为什么 Ace 上总是有 strip 吗?会不会是硬件限制?

谢谢,这一切都非常困惑。

(PS 我已经阅读了官方指南,在向 SO 发布问题以及查看其他相关的 SO 问题之前,我总是先看一下,但是官方指南(通常是这种情况)并不清楚这是我的问题,我无法通过其他问题找到答案,如果已经在这里,我深表歉意。

最佳答案

565 格式是默认格式,因为它可以更快地绘制并且需要更少的处理能力。至于你的SG Ace,我相信前段时间只有部分Android版本支持8888色。

要让我的应用程序背景之一不带,我必须执行以下操作:

1 - 将背景添加到可绘制文件夹

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 - 在 Activity 代码中:

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

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

关于Android 颜色格式(RGB565、ARGB8888),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15177943/

相关文章:

带有 WebView 的 Android GridView 在 OnItemClick 事件中不起作用

java - 如何为 MyLocationOverlay 中的 "you are here"点使用自定义位图?

android - 如何在 Kotlin 中初始化 Array<List<Model>>?

android - 如何在 Android 上将原始相机数据转换为位图

java - 更新 Android 选项卡图标

android - 用 canvas 画画 Android

c# - 使用 Entity Framework 6 从 SQL Server 保存和检索图像(二进制)

ios - YUV 到 Apple A4 上的 RGBA,我应该使用着色器还是 NEON?

java - 请求的数组大小超出 VM 限制

image - 从RGB到YCbCr的转换公式