How can I get to read the pixels in an image?

Please see details of my code below. What I am doing is trying to obtain the pixels for an image. there is an initial image of a certain size, which is then split into smaller portions.
The problem I'm getting is that pixels can not be read past the middle of the original image. I hope I have explained this so it can be understood. I have included the class that I am working on
* To change this template, choose Tools | Templates
* and open the template in the editor.
package MandelbrotConstruction.compression;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.geom.AffineTransform;
import java.awt.image.*;
import java.io.*;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
* @author Charlene Hunter
public class DisplayImg extends JPanel {
    private static BufferedImage image;
    private static ArrayList<Range> rangeLot;
    private static ArrayList<Domain> domainLot;
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        int w = MainFrame.getJPanel1().getWidth();
        int h = MainFrame.getJPanel1().getHeight();
        Graphics2D g2 = (Graphics2D) g;
        File img = MainFrame.getImgFile();
        image = null;
        if (img != null) {
            try {
                image = ImageIO.read(img);
                //filter the image with a grayscale
                ColorConvertOp grayOp = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
                image = grayOp.filter(image, null);
                //scale image to the size of the panel
                AffineTransform at = new AffineTransform();
                at.scale(256.0 / image.getWidth(), 256.0 / image.getHeight());
                AffineTransformOp resizeOp = new AffineTransformOp(at, null);
                image = resizeOp.filter(image, null);
                ArrayList<Range> r = createRanges(image, 3);
                ArrayList<Domain> d = createDomains(image);
                int i = 0;
                for (Domain dom : d) {
                    System.err.println("this is " + i);
                    System.out.println(dom.getPixels());
                    i++;
                CompareClass comparer = new CompareClass(r, d);
            } catch (IOException e) {
                System.err.println("IOException");
        g2.drawImage(image, null, 0, 0);
    public static ArrayList<Range> createRanges(BufferedImage bi, int divisions) {
        int w = bi.getWidth();
        int h = bi.getHeight();
        rangeLot = new ArrayList<Range>();
        int k = (int) Math.pow(2, divisions);
        for (int x = 0; x < w; x = x + (w / k)) {
            for (int y = 0; y < h; y = y + (h / k)) {
                BufferedImage range = bi.getSubimage(x, y, w / k, h / k);
                double[] pix = range.getRaster().getPixels(x, y, range.getWidth(), range.getHeight(), (double[]) null);
                Range r = new Range(x, y, range, pix);
                rangeLot.add(r);
        return rangeLot;
    public static ArrayList<Domain> createDomains(BufferedImage bi) {
        int w = bi.getWidth();
        int h = bi.getHeight();
        domainLot = new ArrayList<Domain>();
        int step = 4;
        for (int x = 0; x < w - step; x = x + step) {
            for (int y = 0; y < h - step; y = y + step) {
                BufferedImage domain = bi.getSubimage(x, y, 2 * step, 2 * step);
                double[] pix = domain.getRaster().getPixels(x, y, domain.getWidth(), domain.getHeight(), (double[]) null);
                Domain d = new Domain(x, y, domain, pix);
                domainLot.add(d);
        return domainLot;
}If what I have included is not sufficient, please let me know. the problem is only arising when the pixels are being obtained for the subimage
Thanks

Hi, the error message I am getting is (i'm printing out the x,y values and width and height so that I can see what going on) the whole image is 512x512, and I am grabbing pixels for squares of 64x64, but when it gets to 256 it throws an exception. I don'd understand why
(x: 0, y: 0)
width: 64, height: 64
done!
(x: 0, y: 64)
width: 64, height: 64
done!
(x: 0, y: 128)
width: 64, height: 64
done!
(x: 0, y: 192)
width: 64, height: 64
done!
(x: 0, y: 256)
width: 64, height: 64
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
        at java.awt.image.ComponentSampleModel.getSampleDouble(ComponentSampleModel.java:807)
        at java.awt.image.SampleModel.getPixels(SampleModel.java:823)
        at java.awt.image.Raster.getPixels(Raster.java:1613)
        at MandelbrotConstruction.compression.DisplayImg.createRanges(DisplayImg.java:83)
        at MandelbrotConstruction.compression.DisplayImg.paintComponent(DisplayImg.java:51)
        at javax.swing.JComponent.paint(JComponent.java:1006)
        at javax.swing.JComponent.paintChildren(JComponent.java:843)
        at javax.swing.JComponent.paint(JComponent.java:1015)
        at javax.swing.JComponent.paintChildren(JComponent.java:843)
        at javax.swing.JComponent.paint(JComponent.java:1015)
        at javax.swing.JLayeredPane.paint(JLayeredPane.java:559)
        at javax.swing.JComponent.paintChildren(JComponent.java:843)
        at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4979)
        at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4925)
        at javax.swing.JComponent.paint(JComponent.java:996)
        at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
        at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
        at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
        at java.awt.Container.paint(Container.java:1709)
        at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
        at sun.awt.RepaintArea.paint(RepaintArea.java:224)
        at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)
        at java.awt.Component.dispatchEventImpl(Component.java:4060)
        at java.awt.Container.dispatchEventImpl(Container.java:2024)
        at java.awt.Window.dispatchEventImpl(Window.java:1791)
        at java.awt.Component.dispatchEvent(Component.java:3819)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Similar Messages

Maybe you are looking for

  • QM - VC integration

    Hi, How VC is integrated in QM . Please mention the complete cycle with tcode. Thanks Jaya

  • Nice MOV from Screen Recording - Import to iMovie looks degraded

    Hi, I am wondering why I have a great MOV file from a Mac screen recording program, with audio, and this looks fantastic when viewed with Quicktime. Then I import into iMovie and it looks much degraded. I don't use iMovie a lot, but I figured MOV qua

  • SAP SD Delivery problem

    Hi guys,     While i entering Shipping point, Delivery date in vlo1 transaction code for creation of delivery. It is giving message that delivery has not been create. Please give me suggestion Kasi

  • I use WIN7, PSE11, LR5 - 'Edit In' PSE11 does not open photos.

    I use WIN7, PSE11, and LR5. LR5's 'Edit In' preference does not open my photos for editing in PSE11. What must I do to use PSE11 as an external editor?

  • HTTPS for posting incoming Invoices

    Currently our vendors are using HTTP to post XML invoices to our XI server. But one of our vendor cannot use HTTP, they have to use HTTPS. So what should we do in our system so our vendor can post invoices to XI server by using HTTPS? do we need do e