Basically, I scramble all the pixels and then reassemble them. But after the reassembly, I lose a massive amount of image quality and color. I also notice that the file size changes which I thought was odd considering its the same pixels.
Notice a massive loss of color and information. I've tried saving it as a PNG instead of JPEG but that didn't seem to change anything. Here's some code.
pixels = new int[width*height];
pixelsLength = pixels.length;
bitmap.getPixels(pixels,0,width,0,0,width,height);
This is where I get the pixels array.
private void encPhaseOne(){
load.setImageResource(R.drawable.imgload1);
int x;
int y;
for(int i = 0; i < RAND_ARRAY_SIZE-1; i+=2){
x = arr1[i];
y = arr1[i+1];
rowSwap(x,y);
}
for(int i = 0; i < RAND_ARRAY_SIZE-1; i+=2){
x = arr4[i];
y = arr4[i+1];
columnSwap(x,y);
}
}
The above is a sample encryption method.
private void decPhaseOne(){
load.setImageResource(R.drawable.imgload3);
int x;
int y;
for(int i = RAND_ARRAY_SIZE-1; i > 0; i-=2){
x = arr4[i];
y = arr4[i-1];
columnSwap(x,y);
}
for(int i = RAND_ARRAY_SIZE-1; i > 0; i-=2) {
x = arr1[i];
y = arr1[i-1];
rowSwap(x,y);
}
}
This is its respective decryption.
private void complete(){
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888,true);
bitmap.setPixels(pixels,0,width,0,0,width,height);
imgUri = getImageUri(this,bitmap);
ContextWrapper cw = new ContextWrapper(getApplicationContext());
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
File file = new File(directory, "ENCIMG" + ".JPEG");
if (!file.exists()) {
Log.d("path", file.toString());
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
done();
}
This is where I save the image.
I can't seem to find where I'm losing so much information