1
我想修改我从Android中的库中采取它的图像。为了修改我需要获取图像的像素值。如何获取在0-255范围内的图像的像素值android
我不想将像素值区分为R,G,B值。我想要的像素值作为单个值
for (x = 0; x < w; x++){
for (y = 0;y < w; y++){
int pixels = bmpimg1.getPixel(x, y);
int alphavalue=Color.alpha(pixels);
int redValue = Color.red(pixels);
int blueValue = Color.blue(pixels);
int greenValue = Color.green(pixels);
totalvalue[x][y]=(redvalue+bluevalue+greenvalue)/3
}
}
//总价值=假设另外redvalue,bluevalue,greenvalue和取平均会给我在该位置的像素值//
当我尝试使用totalvalue重新创建图像,我没有得到我输入的图像。
我在使用Raster.getpixels的java中做了同样的事情,当我尝试创建相同的图像时,我能够获得相同的图像。
Bufferedimage img=ImageIO.read(new File("a.jpg");
Raster raster=img.getData();
for (int x=0;x<w;x++)
{
for(int y=0;y<h;y++)
{
pixels[x][y]=raster.getSample(x,y,0);
pixel[count++]=pixels[x][y];
}
}
当我创建使用的BufferedImage与像素[X] [Y]一个新的形象,我得到原始图像
但在安卓和GetPixel给出负数
所以值我怎样才能得到0-255范围内的每个像素的值,而不分离成RGB值。
请帮我解决这个问题。谢谢
'我怎样才能得到每个像素的值范围0-255没有分离成RGB值... ...所以你使用的是灰度图像(其中A = R = G = B)。或者你想要一个颜色分量的平均值((A + R + G + B)/ 4)? –
谢谢Vyger的帮助,我得到了它的工作我用A = R = G = B来找到灰色图像。 – user2109988