2015-11-17 7 views
5

Ich brauche ein Bild von SD-Karte, erstellen, drehen und speichern geändertes Bild. Ich versuche, diesen CodeSo speichern Sie Exif-Daten nach Bitmap-Copression in 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(); 

zu verwenden, aber ich kippe Änderung in ExifInterface speichern. Löschen Sie einfach alle Tags.

+0

, was genau Sie wollen? Bilddrehung basierend auf Exif-Daten oder möchten Sie Ihre Daten in Exif speichern? – user1140237

Antwort

2

Nur saveAttributes-Methode Speichern Sie die Tag-Daten in der JPEG-Datei.

Prüfung Link

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

Also, wenn Sie Ihren Code dies wird es Ihnen

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

dieser

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

ändern Exif-Tag speichern Daten

Hope this Hilfe

mich bei jedem anderen Thema wissen Lassen

+0

danke, es slove mein Problem – couldDog

+1

@couldDog Ich bin froh, Wenn Sie meine Antwort hilfreich finden, bitte akzeptieren Sie meine Antwort so andere auch Hilfe von hier bekommen Dank – Sandy

+1

@couldDog ist meine Antwort ist, was Sie brauchen oder andere Sache haben Sie versucht, das funktioniert für Sie, weil Sie meine Antwort immer noch nicht angenommen haben – Sandy