本文介绍了该方法的getPixels的说明在Android的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何跨preT从内置的方法的getPixels返回数组的位图?

How do I interpret the returned array from build-in method getPixels for a Bitmap?

下面是我的code:

public void foo() {
    int[] pixels;
    Bitmap bitmapFoo = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.test2);             
    int height = bitmapFoo.getHeight();
    int width = bitmapFoo.getWidth();

    pixels = new int[height * width];

    bitmapFoo.getPixels(pixels, 0, width, 1, 1, width - 1, height - 1);     
}

数组像素获取与返回的值从-988,602,635到1242635509,那是刚刚从几个颜色上我做了一个简单的PNG文件。我怎样才能跨preT即得到此方法返回的数字?

The array "pixels" gets returned with values from -988,602,635 to 1,242,635,509 and that was just from a few colors on a simple PNG file I made. How can I interpret the numbers that get returned from this method?

编辑:我知道这单重presents整数的颜色。我只是不知道如何跨preT这一个整数到RBG和Alpha值组成的颜色。

I realize this single integer represents a color. I just don't understand how to interpret this single integer into the RBG and alpha values that make up the color.

感谢。

PS。如果你问自己,什么是他想要做什么?我试图找出一种方法来动态修改一个​​位图的颜色。

PS. If your asking yourself, "what is he trying to do?" I am trying to figure out a way to dynamically modify the color of a bitmap.

推荐答案

它返回一个int为颜色类。

Col​​or类定义的方法  创建和转换颜色的整数。  颜色是psented为包装整数再$ P $,  由4个字节:α,红,绿,  蓝。该值是未premultiplied,  这意味着任何透明度存储  仅在alpha分量,而不是  在颜色分量。该  组件存储如下  (阿尔法<< 24)| (红<< 16)| (绿色   << 8)|蓝色。每个组件的范围  0..255 0意味着之间没有  贡献了该组件,和  255这意味着100%的贡献。从而  不透明黑色。将0xFF000000(100%  不透明的,但没有从红色有贡献,  格力,蓝色和不透明白色的。将  0xFFFFFFFF的

例如,当您使用画图对象:

For example, when you use the Paint object:

Paint pRed = new Paint();
pRed.setColor(Color.RED);

setColor 期待一个int。 Color.RED的是,他们的pre定义的含义int值红色。

setColor expects an int. Color.RED is that int value for their pre-defined meaning of "red".

这篇关于该方法的getPixels的说明在Android的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:32