Hi tiviniik, thanks for your reply. My image is in variable image.
This is my code:
Code:
//START HERE
int w = image.getWidth();
int h = image.getHeight();
int[] rgbData = new int[w*h];
int[] alpha = new int[rgbData.length];
int[] red = new int[rgbData.length];
int[] green = new int[rgbData.length];
int[] blue = new int[rgbData.length];
image.getRGB(rgbData, 0, w, 0, 0, w, h);
for(int i=0;i<rgbData.length;i++){
alpha[i] = (rgbData[i] & 0xff000000) >> 24;
red[i] = (rgbData[i] & 0xff0000) >> 16;
green[i] = (rgbData[i] & 0x00ff00) >> 8;
blue[i] = (rgbData[i] & 0x0000ff) >> 0;
rgbData[i] = (alpha[i]<<24) | (red[i]<<16) | (green[i]<<8) | (blue[i]);
}//rgb of image
//convert rgbData[] to binary
String[] binImageRed = new String[rgbData.length];
String[] binImageGreen = new String[rgbData.length];
String[] binImageBlue = new String[rgbData.length];
for(int i=0;i<rgbData.length;i++){
binImageRed[i] = Integer.toBinaryString(red[i]);
binImageGreen[i] = Integer.toBinaryString(green[i]);
binImageBlue[i] = Integer.toBinaryString(blue[i]);
while(binImageRed[i].length()<8)
binImageRed[i] = "0"+binImageRed[i];
while(binImageGreen[i].length()<8)
binImageGreen[i] = "0"+binImageGreen[i];
while(binImageBlue[i].length()<8)
binImageBlue[i] = "0"+binImageBlue[i];
}
int k=0; int j=0;
for(int i=0; i<(bin.length*7)/3;i++){ //bin is variable for text, example: 100001
binImageRed[i] = replaceCharAt(binImageRed[i], 7, bin[k].charAt(j));
j++;
if(j>6){
k++;
j=0;
}
binImageGreen[i] = replaceCharAt(binImageGreen[i], 7, bin[k].charAt(j));
j++;
if(j>6){
k++;
j=0;
}
binImageBlue[i] = replaceCharAt(binImageBlue[i], 7, bin[k].charAt(j));
j++;
if(j>6){
k++;
j=0;
}
} //i have the new binRGB
//convert binary to int
int[] rgbDataNew = new int[w*h];
int[] redNew = new int[rgbDataNew.length];
int[] greenNew = new int[rgbDataNew.length];
int[] blueNew = new int[rgbDataNew.length];
for(int i=0;i<rgbDataNew.length;i++){
redNew[i] = Integer.parseInt(binImageRed[i],2);
greenNew[i] = Integer.parseInt(binImageGreen[i],2);
blueNew[i] = Integer.parseInt(binImageBlue[i],2);
rgbDataNew[i] = (alpha[i]<<24) | (redNew[i]<<16) | (greenNew[i]<<8) | (blueNew[i]);
} //we have the new rgbData[]
//create new image
Image imgNew = Image.createRGBImage(rgbDataNew, w, h, false);
//now i want to check the value of rgbData[]
int w1 = imgNew.getWidth();
int h1 = imgNew.getHeight();
int[] rgbData1 = new int[w1*h1];
int[] argb = new int[rgbData.length];
int[] red1 = new int[rgbData1.length];
int[] green1 = new int[rgbData1.length];
int[] blue1 = new int[rgbData1.length];
imgNew.getRGB(rgbData1, 0, w1, 0, 0, w1, h1);
for(int i=0;i<rgbData1.length;i++){
alpha1[i] = (rgbData1[i] & 0xff000000) >> 24;
red1[i] = (rgbData1[i] & 0xff0000) >> 16;
green1[i] = (rgbData1[i] & 0x00ff00) >> 8;
blue1[i] = (rgbData1[i] & 0x0000ff) >> 0;
rgbData1[i] = (alpha1[i]<<24) | (red1[i]<<16) | (green1[i]<<8) | (blue1[i]);
} //from here, i know that rgbData1 has rgbData from original file, not the newRgbData
please help me..
regards,
tbpjap