当我用相机拍照时,它应该被压缩并上传到mysql db。
我检查了函数Bitmap.compress(),输出是在ByteArrayOutputStream中,但我需要File或FileInputStream中的输出。是否可以将ByteArrayOutputStream转换为File?
答案 0 :(得分:1)
是的,它是:
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();
}