A me funziona, pero' ho estatto il valore di ogni pixel con il metodo getRGB() di BufferedImage senza bassare dai raster. Ti posto il codice, provalo e guarda se puoi adattarlo al tuo caso.
codice:
package crypto;
import java.awt.image.*;
import java.io.*;
import javax.imageio.ImageIO;
public class CriptTest {
private static String msg = "Cantami, o Diva, del Pelide Achille " +
"l'ira funesta che infiniti addusse "+
"lutti agli Achei, molte anzi tempo all'Orco "+
"generose travolse alme d'eroi, "+
"e di cani e d'augelli orrido pasto "+
"lor salme abbandonò (così di Giove "+
"l'alto consiglio s'adempia), da quando "+
"primamente disgiunse aspra contesa "+
"il re de' prodi Atride e il divo Achille.\nIncipit ILIADE";
public static void main(String[] args) {
//Leggo l'immagine
File imgFile = new File("C:/Documents and Settings/Simone/Desktop/preview.png");
BufferedImage source = null;
try {
source = ImageIO.read(imgFile);
} catch (IOException ex) {
ex.printStackTrace();
}
//Creo l'immagine di destinazione
BufferedImage dest = new BufferedImage(source.getWidth(),source.getHeight(),BufferedImage.TYPE_INT_ARGB);
//Per comodita tratto char come se fosse int
//Ciclo sui pixel e modifico pixel per pixel mettendo in xor 2 bit del carattere
//con i bit meno significativi di ogni canale
int tmp, pixel, index;
for(int i=0; i<source.getWidth(); i++) {
for(int j=0; j<source.getHeight(); j++) {
pixel = source.getRGB(i,j);
index = (i*source.getHeight())+j;
if(index<msg.length()) {
tmp = msg.charAt(index);
int chan_1 = tmp>>6;
int chan_2 = (tmp^(chan_1<<6))>>4;
int chan_3 = (tmp^(chan_1<<6)^(chan_2<<4))>>2;
int chan_4 = (tmp^(chan_1<<6)^(chan_2<<4)^(chan_3<<2));
pixel = pixel^(chan_1<<24)^(chan_2<<16)^(chan_3<<8)^(chan_4);
}
dest.setRGB(i,j,pixel);
}
}
//Salvo l'immagine
String ext="png";
imgFile = new File("C:/Documents and Settings/Simone/Desktop/Image."+ext);
try {
ImageIO.write(dest,ext,imgFile);
} catch (IOException ex) {
ex.printStackTrace();
}
//Riprova, leggo l'immagine e con il procedimento inverso estraggo i caratteri da ogni pixel
BufferedImage imgMod = null;
try {
imgMod = ImageIO.read(imgFile);
} catch (IOException ex) {
ex.printStackTrace();
}
for(int i=0; i<imgMod.getWidth(); i++) {
for(int j=0; j<imgMod.getHeight(); j++) {
int tmp2 = imgMod.getRGB(i,j)^source.getRGB(i,j);
int chan_1 = tmp2>>24;
int chan_2 = (tmp2^(chan_1<<24))>>16;
int chan_3 = (tmp2^(chan_1<<24)^(chan_2<<16))>>8;
int chan_4 = (tmp2^(chan_1<<24)^(chan_2<<16)^(chan_3<<8));
char c = (char)((chan_1<<6)^(chan_2<<4)^(chan_3<<2)^(chan_4));
if(c!=0) {
System.out.print(c);
}
}
}
}
}