13 Replies Latest reply on Mar 1, 2012 9:09 AM by gimbal2

    Accessing pixel value from BufferdImage

      I am trying to read the pixels of a BufferedImage. For a 24 bit image the type is TYPE.3BYTE.BGR If I use the getPixel() method, the size of array has to be multiplied by 3.

      if (type == BufferedImage.TYPE_3BYTE_BGR) {
      System.out.print(h+" "+ w);
      WritableRaster raster=sourceImage.getRaster();

      int[] pixel= new int[w*h*3];
      raster.getPixels(0, 0, w, h, pixel);
      for (i = 0; i <10; i++) {
      System.out.println(" " + pixel [ i ] );

      Note the size of pixel array, as values of b,g,r are stored one after the other. But if use getRGB() method as:

      if (type == BufferedImage.TYPE_3BYTE_BGR) {
      System.out.print(h + " "+ w);
      int []data=new int[w*h];
      sourceImage.getRGB(0, 0, w, h, data, 0, w);
      for(i=0;i<10 ; i++)
      System.out.println( data [ i ] );

      Note here the size of data array. But the values stored in data array is of format 0xAARRGGBB. The problem is I want the pixel value in integer form, so how do i get it?