Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Getting pixel coordinates of int[] from raster getPixels method

  1. #1
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    124
    Rep Power
    0

    Default Getting pixel coordinates of int[] from raster getPixels method

    Suppose I have a BufferedImage 100x100 in size. To get the pixels of it,
    Java Code:
    BufferedImage image = ImageIO.read("./images/test.png");
    BufferedImage image_out = new BufferedImage(100,100,BufferedImage.TYPE_INT_ARGB);
    int[] data = null;
    data = image.getRaster().getPixels(0,0,100,100, data);
    for (int y = 0; y < image.getHeight() - 1; y ++){
                for (int x = 0; x <image.getWidth() -1; x ++){
                    image_out.setRGB(x, y, new Color(data[i],data[i++],data[i++],data[i++]).getRGB());
                }
    }
    for some reason, "image_out" looks really strange and looks nothing like "image". How should I successfully get the pixel location and get its RGBA data?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    9,936
    Rep Power
    16

    Default Re: Getting pixel coordinates of int[] from raster getPixels method

    Moved from Advanced Java

    db
    danielweigandt likes this.
    Why do they call it rush hour when nothing moves? - Robin Williams

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. converting double to pixel coordinates
    By mkj in forum New To Java
    Replies: 2
    Last Post: 02-05-2012, 06:43 PM
  3. Replies: 6
    Last Post: 01-15-2011, 03:03 PM
  4. Replies: 5
    Last Post: 11-14-2010, 04:28 PM
  5. compare two images pixel by pixel
    By java_bond in forum Advanced Java
    Replies: 6
    Last Post: 03-02-2010, 11:27 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
  •