将bitmap保存到文件夹中

如果想保存在应用的私有目录下,直接context.openFileOutput(),打开应用目录下的输出文件夹

private voidsaveImage(Context context, Bitmap bitmap)

{

//此处范围的所谓外部存储是手机的自带内存32G,64G,并不是SD卡,是否有访问权限

if ( Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {

File newFileDir =newFile(Environment.getExternalStorageDirectory(),"文件名字");

if(!newFileDir.exists()) {

newFileDir.mkdir();

}

File file =newFile(newFileDir, System.currentTimeMillis() +".jpg");

Log.e(TAG,"根目录里面的所有目录:"+ newFileDir.exists());

//打开文件输出流

FileOutputStream os =null;

try{

os =newFileOutputStream(file);

bitmap.compress(Bitmap.CompressFormat.JPEG,100, os);

os.flush();

os.close();

}catch(FileNotFoundException e) {

e.printStackTrace();

}catch(IOException e) {

e.printStackTrace();

}

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容