Results 1 to 4 of 4

Thread: Pixel Data..

  1. #1
    programmer_007's Avatar
    programmer_007 is offline Senior Member
    Join Date
    Aug 2009
    Posts
    125
    Rep Power
    0

    Default Pixel Data..

    have written piece of code to read image's pixel data.
    Java Code:
    public int[] getPixels(String path) throws IOException, InterruptedException
    	{
    		File img_file = new File(path);
    		BufferedImage img = ImageIO.read(img_file);
    		
    		//Array of pixels to hold the pixels of the image 
    		 int pix[] = new int[img.getWidth()*img.getHeight()];
    		 
    		//Grabbing Pixels from the image into the array "pix".
    		 PixelGrabber pg = new PixelGrabber(img,0,0,img.getWidth(),img.getHeight(),pix,0,img.getWidth());
    		 pg.grabPixels();
    
    		 return pix;
    		
    	}
    then i call it in main , using
    Java Code:
    int pixel[] = p.getPixels("/home/sandeep/Desktop/low.jpg");
    	System.out.println(pixel.length);
    	
    	for(int i = 0;i<pixel.length;i++)
    		{
    		System.out.println(Integer.toBinaryString(pixel[i]));
    		}
    it displays... me on console
    Java Code:
    11111111000000000000000000000000
    11111111000000000000000000000000
    11111111000000000000000000000000
    wht i want to know is , as i print the data of each individual pixel..
    is this the useful & correct pixel data ? i mean i doubt , or should i read it by RGB values ?

  2. #2
    programmer_007's Avatar
    programmer_007 is offline Senior Member
    Join Date
    Aug 2009
    Posts
    125
    Rep Power
    0

    Default

    y no replies !! is this a igonoreList...??

  3. #3
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    Depends on your color Model:

    Java Code:
    private ColorModel m_colorModel;
    ...
    m_colorModel = pg.getColorModel();
    Are your colors IndexColorModel or DirectColorModel?

    Java Code:
    public int getRGB(int pixel)
    {
       if ((m_colorModel instanceof IndexColorModel))	  
          return ((IndexColorModel)m_colorModel).getRGB(pixel);
       else
          return ((DirectColorModel)m_colorModel).getRGB(pixel);
    }
    Last edited by mrmatt1111; 03-03-2010 at 10:43 PM.
    My Hobby Project: LegacyClone

  4. #4
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    Also:

    Java Code:
    public int getRed(int pixel)
    {
       if ((m_colorModel instanceof IndexColorModel))	  
          return ((IndexColorModel)m_colorModel).getRed(pixel);
       else
          return ((DirectColorModel)m_colorModel).getRed(pixel);
    }

    Which can be repeated for Green and Blue
    My Hobby Project: LegacyClone

Similar Threads

  1. Scanning Image Pixel by Pixel
    By the_transltr in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2012, 04:01 PM
  2. increase pixel size
    By rosh72851 in forum New To Java
    Replies: 9
    Last Post: 07-31-2012, 07:30 PM
  3. Pixel capture
    By Maiquelnet in forum Advanced Java
    Replies: 1
    Last Post: 11-16-2009, 08:28 PM
  4. Pixel Array?
    By AndrewM16921 in forum New To Java
    Replies: 4
    Last Post: 04-03-2009, 12:08 AM
  5. Replies: 1
    Last Post: 07-17-2007, 04:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •