Android 中位图 getPixels 方法的说明
如何解释位图的内置方法 getPixels 返回的数组?
这是我的代码:
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);
}
返回的数组“pixels”的值从 -988,602,635 到 1,242,635,509,这只是我制作的简单 PNG 文件上的几种颜色。如何解释从此方法返回的数字?
编辑:我意识到这个单个整数代表一种颜色。我只是不明白如何将这个单个整数解释为构成颜色的 RBG 和 alpha 值。
谢谢。
附言。如果你问自己:“他想做什么?”我正在尝试找出一种动态修改位图颜色的方法。
How do I interpret the returned array from build-in method getPixels for a Bitmap?
Here is my 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);
}
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?
Edit: 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.
Thanks.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您还可以执行以下操作来从中检索颜色
一个整数:
You can also do the following to retrieve colors from
an int :
它返回 Color 类的 int。
例如,当您使用 Paint 对象时:
setColor
需要一个 int。 Color.RED 是预定义的“红色”含义的 int 值。It returns an int for the Color class.
For example, when you use the Paint object:
setColor
expects an int. Color.RED is that int value for their pre-defined meaning of "red".更:
Even more:
如果您有 alpha、红色、绿色和蓝色值,则颜色等于 (alpha << 24) + (红色 << 16) + (绿色 << 8) + 蓝色。
要从 int 检索 alpha、红色、绿色和蓝色值,请说 argb:
If you have your alpha, red, green and blue values, your in color is equal to (alpha << 24) + (red << 16) + (green << 8) + blue.
To retrieve your alpha, red, green and blue values from an int, say argb:
除此之外,我想应该是
坐标从0开始吧?
Besides that, I think it should be
The coordinates start from 0, right?