Search in sources :

Example 56 with ExifInterface

use of android.media.ExifInterface in project ttdj by soonphe.

the class ExifInterfaceCompat method getExifDateTime.

private static Date getExifDateTime(String filepath) {
    ExifInterface exif;
    try {
        // ExifInterface does not check whether file path is null or not,
        // so passing null file path argument to its constructor causing SIGSEGV.
        // We should avoid such a situation by checking file path string.
        exif = newInstance(filepath);
    } catch (IOException ex) {
        Log.e(TAG, "cannot read exif", ex);
        return null;
    }
    String date = exif.getAttribute(ExifInterface.TAG_DATETIME);
    if (TextUtils.isEmpty(date)) {
        return null;
    }
    try {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
        formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
        return formatter.parse(date);
    } catch (ParseException e) {
        Log.d(TAG, "failed to parse date taken", e);
    }
    return null;
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 57 with ExifInterface

use of android.media.ExifInterface in project ttdj by soonphe.

the class ExifInterfaceCompat method getExifOrientation.

/**
 * Read exif info and get orientation value of the photo.
 *
 * @param filepath to get exif.
 * @return exif orientation value
 */
public static int getExifOrientation(String filepath) {
    ExifInterface exif;
    try {
        // ExifInterface does not check whether file path is null or not,
        // so passing null file path argument to its constructor causing SIGSEGV.
        // We should avoid such a situation by checking file path string.
        exif = newInstance(filepath);
    } catch (IOException ex) {
        Log.e(TAG, "cannot read exif", ex);
        return EXIF_DEGREE_FALLBACK_VALUE;
    }
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, EXIF_DEGREE_FALLBACK_VALUE);
    if (orientation == EXIF_DEGREE_FALLBACK_VALUE) {
        return 0;
    }
    // We only recognize a subset of orientation tag values.
    switch(orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            return 90;
        case ExifInterface.ORIENTATION_ROTATE_180:
            return 180;
        case ExifInterface.ORIENTATION_ROTATE_270:
            return 270;
        default:
            return 0;
    }
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException)

Example 58 with ExifInterface

use of android.media.ExifInterface in project taquindroid by remram44.

the class ImageTools method getOrientation.

public static int getOrientation(Context context, Uri photoUri) {
    try {
        InputStream istream = context.getContentResolver().openInputStream(photoUri);
        if (istream == null)
            return ExifInterface.ORIENTATION_UNDEFINED;
        File outputDir = context.getCacheDir();
        String extension = getExtension(photoUri.getPath());
        File tempfile = File.createTempFile("taquindroid", extension, outputDir);
        FileOutputStream ostream = new FileOutputStream(tempfile);
        byte[] buffer = new byte[4096];
        int len;
        while ((len = istream.read(buffer)) != -1) ostream.write(buffer, 0, len);
        ostream.close();
        istream.close();
        ExifInterface exif = new ExifInterface(tempfile.getAbsolutePath());
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
        if (!tempfile.delete())
            Log.e("TAQUINDROID", String.format("Couldn't delete teporary file %s", tempfile.getAbsolutePath()));
        return orientation;
    } catch (IOException e) {
        Log.e("TAQUINDROID", "Error reading image orientation");
        return ExifInterface.ORIENTATION_UNDEFINED;
    }
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ExifInterface(android.media.ExifInterface) IOException(java.io.IOException) File(java.io.File)

Example 59 with ExifInterface

use of android.media.ExifInterface in project Remindy by abicelis.

the class EditImageAttachmentActivity method checkExifAndFixImageRotation.

private void checkExifAndFixImageRotation() {
    try {
        ExifInterface ei = new ExifInterface(new File(FileUtil.getImageAttachmentDir(this), mImageAttachment.getImageFilename()).getAbsolutePath());
        int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
        switch(orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                mRotation = 90;
                applyPendingRotation();
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                mRotation = 180;
                applyPendingRotation();
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                mRotation = 270;
                applyPendingRotation();
                break;
            case ExifInterface.ORIENTATION_NORMAL:
            default:
                break;
        }
    // ei.setAttribute(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    } catch (IOException e) {
    /*Do nothing*/
    }
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException) File(java.io.File)

Example 60 with ExifInterface

use of android.media.ExifInterface in project Lazy by l123456789jy.

the class BitmapUtil method getImageDegree.

/**
 * 读取图片属性:图片被旋转的角度
 *
 * @param path 图片绝对路径
 * @return 旋转的角度
 */
public static int getImageDegree(String path) {
    int degree = 0;
    try {
        ExifInterface exifInterface = new ExifInterface(path);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch(orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return degree;
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Aggregations

ExifInterface (android.media.ExifInterface)153 IOException (java.io.IOException)93 Paint (android.graphics.Paint)32 Bitmap (android.graphics.Bitmap)26 InputStream (java.io.InputStream)21 File (java.io.File)17 BitmapFactory (android.graphics.BitmapFactory)16 Matrix (android.graphics.Matrix)15 FileInputStream (java.io.FileInputStream)15 Point (android.graphics.Point)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ErrnoException (android.system.ErrnoException)10 BufferedInputStream (java.io.BufferedInputStream)10 FileDescriptor (java.io.FileDescriptor)10 FileNotFoundException (java.io.FileNotFoundException)10 SuppressLint (android.annotation.SuppressLint)9 FileOutputStream (java.io.FileOutputStream)8 Cursor (android.database.Cursor)7 AssetFileDescriptor (android.content.res.AssetFileDescriptor)6 Bundle (android.os.Bundle)5