【发布时间】:2012-08-02 10:11:28
【问题描述】:
我正在尝试使用 androids ndk 进行一些简单的图像过滤,但似乎在获取和设置位图的 rgb 值时遇到了一些问题。
我已经去掉了所有的实际处理,只是试图将位图的每个像素都设置为红色,但我最终得到了一个蓝色的图像。我认为我忽略了一些简单的事情,但感谢您提供任何帮助。
static void changeIt(AndroidBitmapInfo* info, void* pixels){
int x, y, red, green, blue;
for (y=0;y<info->height;y++) {
uint32_t * line = (uint32_t *)pixels;
for (x=0;x<info->width;x++) {
//get the values
red = (int) ((line[x] & 0xFF0000) >> 16);
green = (int)((line[x] & 0x00FF00) >> 8);
blue = (int) (line[x] & 0x0000FF);
//just set it to all be red for testing
red = 255;
green = 0;
blue = 0;
//why is the image totally blue??
line[x] =
((red << 16) & 0xFF0000) |
((green << 8) & 0x00FF00) |
(blue & 0x0000FF);
}
pixels = (char *)pixels + info->stride;
}
}
我应该如何获取并设置每个像素的 rgb 值??
更新答案
正如下面所指出的,似乎使用了小端,所以在我的原始代码中,我只需要切换红色和蓝色变量:
static void changeIt(AndroidBitmapInfo* info, void* pixels){
int x, y, red, green, blue;
for (y=0;y<info->height;y++) {
uint32_t * line = (uint32_t *)pixels;
for (x=0;x<info->width;x++) {
//get the values
blue = (int) ((line[x] & 0xFF0000) >> 16);
green = (int)((line[x] & 0x00FF00) >> 8);
red = (int) (line[x] & 0x0000FF);
//just set it to all be red for testing
red = 255;
green = 0;
blue = 0;
//why is the image totally blue??
line[x] =
((blue<< 16) & 0xFF0000) |
((green << 8) & 0x00FF00) |
(red & 0x0000FF);
}
pixels = (char *)pixels + info->stride;
}
}
【问题讨论】:
标签: android c image-processing android-ndk bit-manipulation