Senhores, estou necessitando salvar um objeto Image no sistema de arquivo.
Para tal estou agindo da seguinte forma:
- chamo o método
public static final byte[] getImageByteArray(Image image) {
int raw[] = new int[image.getWidth() * image.getHeight()];
image.getRGB(raw, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
byte rawByte[] = new byte[image.getWidth() * image.getHeight() * 4];
int n = 0;
//
for(int i = 0; i < raw.length; i++) {
int ARGB = raw[i];
int a = (ARGB & 0xff000000) >> 24;
int r = (ARGB & 0xff0000) >> 16;
int g = (ARGB & 0xff00) >> 8;
int b = ARGB & 0xff;
rawByte[n] = (byte)b;
rawByte[n + 1] = (byte)g;
rawByte[n + 2] = (byte)r;
rawByte[n + 3] = (byte)a;
n += 4;
}
//
raw = null;
//
return rawByte;
}
que é responsavel por serealizar o meu objeto Image.
Só que quando vou abrir o arquivo gerado a imagem não está visível. Me falaram que eu tenho que utilizar algum algoritmo de compressão de imagem para a imagem poder ser lida. corretamente. Algum conhece alguma API que faça isso ou outra forma de persistir um Image.