如何保存后的And​​r​​oid位警察pression Exif数据中 [英] How to save Exif data after bitmap coppression in Android

查看:109
本文介绍了如何保存后的And​​r​​oid位警察pression Exif数据中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从SD卡获取图像,创建,旋转和保存更改的图像。
我尝试使用这个code

I need to get image from sd card, create, rotate and save changed image. I try to use this code

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();

但我不能保存变化ExifInterface。这只是清除所有标签。

But i cant save change in ExifInterface. This just clear all the tags.

推荐答案

saveAttributes方法仅标签数据保存到JPEG文件。

saveAttributes method only Save the tag data into the JPEG file.

检查此链接

http://developer.android.com/reference/android/media/ExifInterface.html#saveAttributes()

所以,如果你改变了code此

So if you change your code this

bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);

这个

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

这将节省您的EXIF标签数据

it will save you exif tag data

希望这有助于

让我知道任何其他问题的情况下

Let me know in case of any other issue

这篇关于如何保存后的And​​r​​oid位警察pression Exif数据中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆