试图了解Bitmap.Config.ARBG_8888 [英] Trying to understand Bitmap.Config.ARBG_8888

查看:85
本文介绍了试图了解Bitmap.Config.ARBG_8888的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解ARGB_8888格式的彩色字节的打包.

I'm trying to understand packing of color bytes for ARGB_8888 format.

文档指出应该打包使用以下公式完成:

The documentation states that packing should be done using this formula:

int color = (A & 0xff) << 24 | (B & 0xff) << 16 | (G & 0xff) << 8 | (R & 0xff);

但是不应该这样:

int color = (A & 0xff) << 24 | (R & 0xff) << 16 | (G & 0xff) << 8 | (B & 0xff);

当我从具有所有红色像素的ARGB_8888颜色编码位图中解压缩一个样本像素时,我正在使用:

When I unpack a sample pixel from a ARGB_8888 color encoded bitmap that has all red pixels, I'm using:

    final int r = (p >> 16) & 0xff;
    final int g = (p >> 8) & 0xff;
    final int b = p & 0xff;

这确实为我返回了每种颜色的正确值.

Which indeed returns me correct values for every color.

我的意思是,说明文件有误还是我遗漏了一些东西?

My point is, is it the documentation wrong or I'm missing something?

推荐答案

是的,您是正确的,文档是错误的.如果您查看

Yes, you are correct and the documentation is wrong. If you look at the Android source code for Color.java it's done the second way:

* <h4>Encoding</h4>
* <p>The four components of a color int are encoded in the following way:</p>
* <pre class="prettyprint">
* int color = (A & 0xff) << 24 | (R & 0xff) << 16 | (G & 0xff) << 8 | (B & 0xff);
* </pre>

再往下走...

@ColorInt
public static int argb(
        @IntRange(from = 0, to = 255) int alpha,
        @IntRange(from = 0, to = 255) int red,
        @IntRange(from = 0, to = 255) int green,
        @IntRange(from = 0, to = 255) int blue) {
    return (alpha << 24) | (red << 16) | (green << 8) | blue;
}

这篇关于试图了解Bitmap.Config.ARBG_8888的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆