import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.image.*;

public class ImageToPixels
{
  int[] pixels;

  public ImageToPixels(Image image, int width, int height) {
    pixels = new int[width * height];
    PixelGrabber pg =
      new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
    try {
      pg.grabPixels();
    } catch (InterruptedException e) {
      System.out.println("interrupted waiting for pixels!");
      return;
    }
    if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
      System.out.println("image fetch aborted or errored");
      return;
    }
  }

  public int[] grabPixels() {
    return pixels;
  }
}
