从文件地址读取为Bitmap:
public static Bitmap getBitmapFromUri(Context context, String filePath) {
try {
Uri uri = Uri.parse(filePath);
Bitmap bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
return bitmap;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
写入Bitmap到指定文件地址:
public static boolean saveBitmap(Bitmap bm, File f) {
try {
FileOutputStream out = new FileOutputStream(f);
bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
}
return false;
}
网友评论