/* get raw data of image */
DataBuffer imageDataBuffer = img.getRaster().getDataBuffer();
int[] data = (((DataBufferInt)imageDataBuffer).getData());
/* create one ImageLine that will be refilled and written to png */
ImageLineByte bline = new ImageLineByte(imgInfo);
byte[] line = bline.getScanline();
for (int i = 0; i < lines; i++) {
for (int d = 0; d < img.getWidth(); d++) {
int val = data[i*img.getWidth()+d];
line[3*d+0] = (byte) (val >> 16);