[英]Android - Compress Bitmap to upload to MySQL Database
When I take a photo with the camera it should be compressed and uploaded to mysql db. 当我用相机拍摄照片时,应将其压缩并上传到mysql db。
I checked the function Bitmap.compress() and the output is in a ByteArrayOutputStream but I need the output in File or FileInputStream. 我检查了功能Bitmap.compress(),输出在ByteArrayOutputStream中,但是我需要在File或FileInputStream中输出。 Is it poossible to convert ByteArrayOutputStream into File? 可以将ByteArrayOutputStream转换为File吗?
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.