0

When I take a photo with the camera it should be compressed and uploaded to mysql db.

I checked the function Bitmap.compress() and the output is in a ByteArrayOutputStream but I need the output in File or FileInputStream. Is it poossible to convert ByteArrayOutputStream into File?

ninjaxelite
  • 1,139
  • 2
  • 20
  • 43

1 Answers1

1

Yes, it is :

OutputStream outStream = null;
ByteArrayOutputStream byteOutStream = null;
try {  
    File file = new File(Environment.getExternalStorageDirectory() + "/myimage.png");
    outStream = new FileOutputStream(file);
    byteOutStream = new ByteArrayOutputStream();
    byteOutStream.write(bytes);
    byteOutStream.writeTo(outStream);  
} catch (IOException e) {  
    e.printStackTrace();  
} finally {  
    outStream.close();  
}  
2Dee
  • 8,609
  • 7
  • 42
  • 53
  • http://stackoverflow.com/questions/8296248/how-to-convert-outputstream-to-file after that is the compressed image in File? – ninjaxelite Sep 09 '14 at 13:45
  • I updated my answer, see if it works for you, the compressed image should get written to the file. – 2Dee Sep 09 '14 at 13:49