android保存预览图片
16lz
2021-12-21
private void savePic(byte[] data,Rect rect) { File file = new File(Environment.getExternalStorageDirectory(), countflag+".jpg"); Log.e(TAG, "savePic: "+ Environment.getExternalStorageDirectory().getAbsolutePath() ); // 如果文件不存在 file.deleteOnExit(); try{ Boolean createresult = file.createNewFile(); FileOutputStream outStream = new FileOutputStream(file); ByteArrayOutputStream out =new ByteArrayOutputStream(); YuvImage image = new YuvImage(data, ImageFormat.NV21, previewSize.width, previewSize.height, null); //将NV21 data保存成YuvImage //图像压缩 image.compressToJpeg( rect, 70, out); outStream.write(out.toByteArray()); out.close(); // 最后关闭文件输出流 outStream.close(); }catch (Exception e){ Log.e(TAG, "savePic: create file error: ",e ); }}
更多相关文章
- [置顶] AndroidStudio快捷键
- android 一步一步创建jni示例
- Android(安卓)QQ多级列表的实现
- Android(安卓)CTS Test
- android音乐播放器
- Android文件读写
- Android获取文件的MD5值
- 使用Android(安卓)Studio可能会遇到的问题
- NPM 和webpack 的基础使用