2015-02-11 7 views
7

से EXIF ​​रोटेशन प्राप्त करें मैं एक तस्वीर के EXIF ​​रोटेशन को जानना चाहता हूं। जब गैलरी में चित्र प्रदर्शित होता है, तो यह घुमाया नहीं जाता है, लेकिन EXIF ​​जानकारी 'घुमाएं बाएं' के साथ छवि लोड करने के बाद चित्र घुमाया जाता है।एंड्रॉइड: यूआरआई

अब मैं उपयोगकर्ता से पूछना चाहता हूं, अगर वह घुमावदार छवि या मूल का उपयोग करना चाहता है।

मुझे लगता है कि विधि के लिए एक उरी हो और यह एक स्टोर बिटमैप में

InputStream inputStream = PaintroidApplication.applicationContext.getContentResolver().openInputStream(bitmapUri); 
    BitmapFactory.decodeStream(inputStream, null, options); 
    inputStream.close(); 

अब मैं रोटेशन निर्धारण करेगा ExifInterface उपयोग करना चाहते हैं, लेकिन ExifInterface एक पथ की आवश्यकता है:

 ExifInterface exif = new ExifInterface(bitmapUri.getPath()); 
     rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 

अब मुझे पथ के साथ समस्या है और लॉगकैट निम्न संदेश दिखाता है:

ई/जेएचईएडी: '/ दस्तावेज़/छवि: 15035' नहीं खोल सकता

मैं इस समस्या को कैसे हल कर सकता हूं या EXIF ​​जानकारी जानने के लिए कोई अन्य समाधान है?

+0

मैं तुम्हें पथ की पहचान करने के लिए एक पिकर (REQUEST_IMAGE_PICK) का उपयोग कर रहे अनुमान लगा रहा हूँ छवि के लिए? – Neil

+0

मुझे यहां एक समान प्रश्न मिला है http://stackoverflow.com/questions/19834842/android-gallery-on-kitkat-returns- अलग-uri-for-intent-action-get-content – Neil

उत्तर

1

समस्या अनुमतियों पर है। अपने मैनिफेस्ट में अनुमति android.permission.READ_EXTERNAL_STORAGE जोड़ें।

6

मुझे इस समस्या का सामना करना पड़ा है। वी 1 9 और उससे ऊपर के एपीआई द्वारा प्रदान किए गए पिकर्स आपको यह परिणाम दे सकते हैं। कोशिश के नीचे कोड दें, अपनी समस्या का समाधान करना चाहिए।


आपका संशोधित कोड

String path = FileUtility.getRealPathFromURI(context, Uri.parse(bitmapUri.getPath()); 
ExifInterface exif = new ExifInterface(path); 
rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 

FileUtility.java

/** 
* Gets the real path from file 
* @param context 
* @param contentUri 
* @return path 
*/ 
public static String getRealPathFromURI(Context context, Uri contentUri) { 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
     return getPathForV19AndUp(context, contentUri); 
    } else { 
     return getPathForPreV19(context, contentUri); 
    } 
} 

/** 
* Handles pre V19 uri's 
* @param context 
* @param contentUri 
* @return 
*/ 
public static String getPathForPreV19(Context context, Uri contentUri) { 
    String res = null; 

    String[] proj = { MediaStore.Images.Media.DATA }; 
    Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null); 
    if(cursor.moveToFirst()){; 
     int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
     res = cursor.getString(column_index); 
    } 
    cursor.close(); 

    return res; 
} 

/** 
* Handles V19 and up uri's 
* @param context 
* @param contentUri 
* @return path 
*/ 
@TargetApi(Build.VERSION_CODES.KITKAT) 
public static String getPathForV19AndUp(Context context, Uri contentUri) { 
    String wholeID = DocumentsContract.getDocumentId(contentUri); 

    // Split at colon, use second item in the array 
    String id = wholeID.split(":")[1]; 
    String[] column = { MediaStore.Images.Media.DATA }; 

    // where id is equal to 
    String sel = MediaStore.Images.Media._ID + "=?"; 
    Cursor cursor = context.getContentResolver(). 
      query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
        column, sel, new String[]{ id }, null); 

    String filePath = ""; 
    int columnIndex = cursor.getColumnIndex(column[0]); 
    if (cursor.moveToFirst()) { 
     filePath = cursor.getString(columnIndex); 
    } 

    cursor.close(); 
    return filePath; 
} 
+1

यह कोड लगभग मेरे लिए काम करता है । धन्यवाद। जोड़ने के लिए एक चीज है दस्तावेज़ कंट्रैक्ट.getDocumentId (contentUri) केवल तभी काम करता है जब DocumentsContract.isDocumentUri सत्य वापस आती है। इसलिए यदि यह है> = 19 और isDocumentUri है तो getPathForV19AndUp का उपयोग करें। अन्यथा GetPathForPreV19 का उपयोग करें। – RyanShao

संबंधित मुद्दे