Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Norm

Thread: Read the pixel detail in shorter time

  1. #1
    lnkhanal is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Question Read the pixel detail in shorter time

    Hi there,
    I need to read all the pixels of an image to process later. I successfully did that too. But my doubt is, my code takes more than 10 seconds to read all the pixels values in my Inter i3 processor.
    I think the 10 seconds time is too much and can be minimized by any how. Do you please have any idea to shorten that time?
    Thank you in advance:)
    My Java Code is:
    Java Code:
     public int[] getImagePixels(BufferedImage image)
    {
        PixelGrabber grabber;
        
        int height = image.getHeight();
        int width = image.getWidth();
        
        
        System.out.println("Height = "+height+"\n Width = "+width);
        int[] pixels = new int[height*width];
        try
        {
             
            
             for(int j = 0;j< height;j++){
                 System.out.println("Row: "+(++j));
                   for(int i = 0;i< width;i++){
                       
                       int pixel = image.getRGB(i, j);
                       int a = (pixel>>24) & 0xff;
                       int r = (pixel>>16) & 0xff;
                       int g = (pixel>>8) & 0xff;
                       int b = (pixel>>4) & 0xff;
                       
                       System.out.println("Alpha,Red,Green and Blue Components are:"+a+" "+r+" "+g+" "+b+" \n");
                       
                   }
                  System.out.println("\n");
              }
    
            grabber = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
           
            grabber.grabPixels();
           
             
        }
        catch (Exception e)
        {
        }
        return pixels;
    }
    Last edited by Norm; 11-16-2011 at 11:16 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,578
    Rep Power
    25

    Default Re: Read the pixel detail in shorter time

    You don't say how large your image is.
    Does the time include that taken by println()? Comment that out and see how long it takes.
    DarrylBurke likes this.

  3. #3
    lnkhanal is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: Read the pixel detail in shorter time

    Oh Yes!
    The println() had taken almost all the time. After commenting the line it could possible to read all the pixels within very few seconds, Neatbeans showed me 0 seconds..:)
    My image is of 249X240 pixels in size.
    Thanks for your suggestion:):)

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. Shorter code: Spell Out Numbers
    By arnelcolar in forum New To Java
    Replies: 11
    Last Post: 04-14-2011, 04:31 PM
  3. How to read the pixel values of a jpg binary image
    By carindia in forum New To Java
    Replies: 2
    Last Post: 09-17-2010, 06:19 PM
  4. compare two images pixel by pixel
    By java_bond in forum Advanced Java
    Replies: 6
    Last Post: 03-02-2010, 11:27 AM
  5. How do I make ImageIcon strings shorter.
    By Singing Boyo in forum New To Java
    Replies: 7
    Last Post: 03-10-2009, 09:29 AM

Tags for this Thread

Posting Permissions

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