I have this method here, which converts an image to a byte array.

```
public byte[] imageToCompressedByteArray(Image image) throws IOException {
//load the image
String f = "C:\\Users\\mamed\\Documents\\NetBeansProjects\\Main\\src\\resources\\accept.png";
image = ImageIO.read(new FileInputStream(new File(f)));

// get image size
int width = image.getWidth(null);
int height = image.getHeight(null);

try {
  int[] imageSource = new int[width * height];
  PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, imageSource, 0, width);
  pg.grabPixels();

  ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); 
  GZIPOutputStream zippedStream = new GZIPOutputStream(byteStream);
  ObjectOutputStream objectStream = new ObjectOutputStream(zippedStream);
  objectStream.writeShort(width);
  objectStream.writeShort(height);
  objectStream.writeObject(imageSource);
  objectStream.flush();
  objectStream.close();
  return byteStream.toByteArray();
}
catch (Exception e) {
  throw new IOException("Error storing image in object: " + e);
}

```

}

However, i can't get this to work, i mean, it can't load the image and convert it, and i don't have an idea what the problem can be.