Tôi cần lấy hình ảnh từ thẻ sd, tạo, xoay và lưu hình ảnh đã thay đổi. Tôi cố gắng sử dụng mã nàyCách lưu dữ liệu Exif sau bitmap coppression trong Android
Bitmap original = BitmapFactory.decodeFile(file.getAbsolutePath());
ExifInterface originalExif = new ExifInterface(file.getAbsolutePath());
int orientation = originalExif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
Matrix matrix = new Matrix();
int rotate = 90;
if(orientation == ExifInterface.ORIENTATION_ROTATE_90){
rotate = 180;
}else if(orientation == ExifInterface.ORIENTATION_ROTATE_180){
rotate = 270;
}else if(orientation == ExifInterface.ORIENTATION_ROTATE_270){
rotate = 0;
}
matrix.postRotate(rotate);
Bitmap bitmap = Bitmap.createBitmap(original, 0, 0, original.getWidth(), original.getHeight(), matrix, true);
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
original.recycle();
bitmap.recycle();
}
ExifInterface newExif = new ExifInterface(file.getAbsolutePath());
newExif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_ROTATE_90));
newExif.saveAttributes();
Nhưng tôi không thể lưu thay đổi trong ExifInterface. Điều này chỉ rõ ràng tất cả các thẻ.
chính xác bạn muốn gì? hình ảnh xoay dựa trên dữ liệu exif hoặc bạn muốn lưu dữ liệu của bạn trong exif? – user1140237