android 保存图片,及将图片更新到图库


 **保存图片

public static File saveImage(Bitmap bmp) { File appDir = new File(Environment.getExternalStorageDirectory(), "文件夹名字"); if (!appDir.exists()) { appDir.mkdir(); } String fileName = System.currentTimeMillis() + ".jpg"; File file = new File(appDir, fileName); try { FileOutputStream fos = new FileOutputStream(file); bmp.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }

**把文件插入图库

try {
    MediaStore.Images.Media.insertImage(context.getMyContext().getContentResolver(), file.getAbsolutePath(), fileName, null);
} catch (FileNotFoundException e) {
    e.printStackTrace();
}

**最后通知图库进行更新

                context.getMyContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file.getPath())));

 




免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM