Java 如何在android中获取0-255范围内的图像像素值

Java 如何在android中获取0-255范围内的图像像素值,java,android,image,image-processing,Java,Android,Image,Image Processing,我正在尝试修改我在android中从图库中获取的图像。为了修改,我需要得到图像的像素值 我不想将像素值区分为R、G、B值。我希望像素值作为单个值 for (x = 0; x < w; x++){ for (y = 0;y < w; y++){ int pixels = bmpimg1.getPixel(x, y); int alp

我正在尝试修改我在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
                         }
                         }
(x=0;x{ 对于(y=0;y //totalvalue=假设加上redvalue、bluevalue、greenvalue和平均值,将得到该位置的像素值//

当我尝试使用totalvalue重新创建图像时,我没有得到作为输入的图像

我在java中使用Raster.getpixels做了同样的操作,当我尝试创建相同的图像时,我能够得到相同的图像

              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 img=ImageIO.read(新文件(“a.jpg”);
光栅=img.getData();

对于(int x=0;x由于所有红色、蓝色和绿色分量的值最多可达255,所以不能将它们相加得到一个unic颜色值(例如,因为1+2+3=2+3+1)

您必须使用该方法将颜色值存储在大于255的数字中

color = redValue*2^16 + greenValue*2^8 + blueValue
您应该能够找出如何从这个唯一的值中检索红色、蓝色和绿色


祝你好运

我如何才能在不分离为RGB值的情况下获得0-255范围内每个像素的值
…因此你使用的是灰度图像(其中a=R=G=B)。或者你想要颜色分量的平均值((a+R+G+B)/4?谢谢Vyger的帮助,我使用了a=R=G=B来查找灰度图像。