Java Code Examples for android.support.media.ExifInterface#getAttribute()

The following examples show how to use android.support.media.ExifInterface#getAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExifUtil.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
public static ExifItem[] retrieveExifData(Context context, Uri uri) {
    ExifInterface exif = getExifInterface(context, AlbumItem.getInstance(context, uri));
    if (exif != null) {
        String[] exifTags = getExifTags();
        ExifItem[] exifData = new ExifItem[exifTags.length];
        for (int i = 0; i < exifTags.length; i++) {
            String tag = exifTags[i];
            String value = exif.getAttribute(tag);
            ExifItem exifItem = new ExifItem(tag, value);
            exifData[i] = exifItem;
        }
        return exifData;
    }
    return null;
}
 
Example 2
Source File: Util.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
public static int[] getImageDimensions(Context context, Uri uri) {
    int[] dimensions = new int[]{0, 0};

    try {
        InputStream is = context.getContentResolver().openInputStream(uri);

        //try exif
        String mimeType = MediaType.getMimeType(context, uri);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
                && MediaType.doesSupportExifMimeType(mimeType)
                && is != null) {
            ExifInterface exif = new ExifInterface(is);
            if (exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH) != null
                    && exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH) != null) {
                int width = (int) ExifUtil.getCastValue(exif, ExifInterface.TAG_IMAGE_WIDTH);
                int height = (int) ExifUtil.getCastValue(exif, ExifInterface.TAG_IMAGE_LENGTH);
                if (width != 0 && height != 0) {
                    return new int[]{width, height};
                }
            }
        }

        //exif didn't work
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(is, new Rect(0, 0, 0, 0), options);
        dimensions[0] = options.outWidth;
        dimensions[1] = options.outHeight;

        if (is != null) {
            is.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return dimensions;
}
 
Example 3
Source File: ExifUtil.java    From Camera-Roll-Android-App with Apache License 2.0 4 votes vote down vote up
public static Object getCastValue(ExifInterface exif, String tag)
        throws NumberFormatException, NullPointerException {
    String value = exif.getAttribute(tag);
    return castValue(tag, value);
}