1

I am trying to implement a Steganography project for Android. I have manipulated the pixel values and created a new bitmap. Now when i store the bitmap into the phone memory or memory card using

//fo denotes File output Stream
Bitmap.compress(Bitmap.CompressFormat.JPEG,100,fo);
//OR
Bitmap.compress(Bitmap.CompressFormat.PNG,100,fo);   

and try accessing the pixels back using getPixels();

the values are reverted back to the original bitmap i.e. rather than the manipulated bitmap. Can anybody figure why this is?

Desert Ice
  • 4,461
  • 5
  • 31
  • 58

2 Answers2

1

JPEG is lossy, it can change pixel values when compressing. Use PNG if you want to preserve colors.

yoah
  • 7,180
  • 2
  • 30
  • 30
1
File myDir=new File("/sdcard/saved_images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete (); 
try {
       FileOutputStream out = new FileOutputStream(file);
       finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
       out.flush();
       out.close();

} catch (Exception e) {
       e.printStackTrace();
}

look at this answer https://stackoverflow.com/a/7887114/964741

Community
  • 1
  • 1
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
  • There is no problem in actually creating the file, but the pixel values of the bitmap changes.Is there a way to prevent it? – Desert Ice Nov 27 '11 at 08:41
  • For example the bitmap values for red , blue and green were 8,8,15 but after saving the bitmap the values were 16 16 16.Can anybody tell me how i can prevent this? – Desert Ice Nov 27 '11 at 14:08