BitmapConfig中的几种ARGB值

作者: 金馆长说 | 来源:发表于2017-04-06 01:02 被阅读176次

    我们创建图片的时候一般需要指定bitmap的色彩值
    Bitmap有一个Config内部枚举里面有四种色彩模式
    ARGB是四种颜色的简称,RGB也称为三原色。
    A alpha 透明色
    R RED 红色
    G green 绿色
    B blue 蓝色

    ALPHA_8 代表8位Alpha位图 1字节
    ARGB_4444 代表16位ARGB位图
    ARGB_8888 代表32位ARGB位图
    RGB_565 代表8位RGB位图
    官方推荐使用ARGB_8888作为色彩模式,节省内存而且清晰度高

    /**
         * Possible bitmap configurations. A bitmap configuration describes
         * how pixels are stored. This affects the quality (color depth) as
         * well as the ability to display transparent/translucent colors.
         */
        public enum Config {
            // these native values must match up with the enum in SkBitmap.h
    
            /**
             * Each pixel is stored as a single translucency (alpha) channel.
             * This is very useful to efficiently store masks for instance.
             * No color information is stored.
             * With this configuration, each pixel requires 1 byte of memory.
             */
            ALPHA_8     (1),
    
            /**
             * Each pixel is stored on 2 bytes and only the RGB channels are
             * encoded: red is stored with 5 bits of precision (32 possible
             * values), green is stored with 6 bits of precision (64 possible
             * values) and blue is stored with 5 bits of precision.
             *
             * This configuration can produce slight visual artifacts depending
             * on the configuration of the source. For instance, without
             * dithering, the result might show a greenish tint. To get better
             * results dithering should be applied.
             *
             * This configuration may be useful when using opaque bitmaps
             * that do not require high color fidelity.
             */
            RGB_565     (3),
    
            /**
             * Each pixel is stored on 2 bytes. The three RGB color channels
             * and the alpha channel (translucency) are stored with a 4 bits
             * precision (16 possible values.)
             *
             * This configuration is mostly useful if the application needs
             * to store translucency information but also needs to save
             * memory.
             *
             * It is recommended to use {@link #ARGB_8888} instead of this
             * configuration.
             *
             * Note: as of {@link android.os.Build.VERSION_CODES#KITKAT},
             * any bitmap created with this configuration will be created
             * using {@link #ARGB_8888} instead.
             *
             * @deprecated Because of the poor quality of this configuration,
             *             it is advised to use {@link #ARGB_8888} instead.
             */
            @Deprecated
            ARGB_4444   (4),
    
            /**
             * Each pixel is stored on 4 bytes. Each channel (RGB and alpha
             * for translucency) is stored with 8 bits of precision (256
             * possible values.)
             *
             * This configuration is very flexible and offers the best
             * quality. It should be used whenever possible.
             */
            ARGB_8888   (5);
    
            final int nativeInt;
    
            private static Config sConfigs[] = {
                null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888
            };
    
            Config(int ni) {
                this.nativeInt = ni;
            }
    
            static Config nativeToConfig(int ni) {
                return sConfigs[ni];
            }
        }
    
    Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
    

    相关文章

      网友评论

        本文标题:BitmapConfig中的几种ARGB值

        本文链接:https://www.haomeiwen.com/subject/nhdfattx.html