int[] pixels = new int[img.getWidth() * img.getHeight()]; int w = img.getWidth(), h = img.getHeight();
int[] pixels = new int[w * h]; byte[][] sprite = new byte[w][h];
    public void importImg(File f)    {        try        {            if (f == null)                return;            if (!f.exists())                throw new FileNotFoundException();            BattleSprite sp = getSelectedSprite();            BufferedImage img = ImageIO.read(f);            if (img == null)                System.out                    .println("How can img be null here!? battle sprite editor");            byte[][] sprite = new byte[img.getWidth()][img.getHeight()];            int[] pixels = new int[img.getWidth() * img.getHeight()];            int w = img.getWidth(), h = img.getHeight();            PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pixels, 0, w);            try            {                pg.grabPixels();            }            catch (InterruptedException e)            {                System.err.println("Interrupted waiting for pixels!");                return;            }            for (int j = 0; j < h; j++)            {                for (int i = 0; i < w; i++)                {                    sprite[i][j] = ((Byte) BITMAP_REV_PAL.get(new Integer(                        pixels[j * w + i]))).byteValue();                }            }            sp.setSprite(sprite);            da.setImage(sp.getSprite());            da.repaint();        }        catch (IOException e)        {            System.out.println("Unable to read image: " + f.toString());            e.printStackTrace();        }        catch (NullPointerException e)        {            JOptionPane.showMessageDialog(mainWindow,                "Invalid colors in image. Image may only contain "                    + "colors existing in a 16-color non-paletted BMP.",                "Error Reading Image", JOptionPane.ERROR_MESSAGE);        }    }