Search in sources :

Example 71 with ExifInterface

use of android.media.ExifInterface in project SmartAndroidSource by jaychou2012.

the class BaseImageDecoder method defineExifOrientation.

protected ExifInfo defineExifOrientation(String imageUri) {
    int rotation = 0;
    boolean flip = false;
    try {
        ExifInterface exif = new ExifInterface(Scheme.FILE.crop(imageUri));
        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch(exifOrientation) {
            case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                flip = true;
            case ExifInterface.ORIENTATION_NORMAL:
                rotation = 0;
                break;
            case ExifInterface.ORIENTATION_TRANSVERSE:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotation = 90;
                break;
            case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotation = 180;
                break;
            case ExifInterface.ORIENTATION_TRANSPOSE:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotation = 270;
                break;
        }
    } catch (IOException e) {
        L.w("Can't read EXIF tags from file [%s]", imageUri);
    }
    return new ExifInfo(rotation, flip);
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException)

Example 72 with ExifInterface

use of android.media.ExifInterface in project Android-skin-support by ximsfei.

the class ImageUtils method getImageRotateAngle.

public static int getImageRotateAngle(String filePath) {
    ExifInterface exif;
    try {
        exif = new ExifInterface(filePath);
    } catch (IOException e) {
        e.printStackTrace();
        exif = null;
    }
    int angle = 0;
    if (exif != null) {
        int ori = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
        switch(ori) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                angle = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                angle = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                angle = 270;
                break;
            default:
                angle = 0;
                break;
        }
    }
    return angle;
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException)

Example 73 with ExifInterface

use of android.media.ExifInterface in project mobile-android by photo.

the class ImageUtils method getExifDateTime.

/**
 * Returns number of milliseconds since Jan. 1, 1970, midnight. Returns -1
 * if the date time information if not available.
 *
 * @param attributeName
 * @throws IOException
 */
public static long getExifDateTime(String fileName) throws IOException {
    ExifInterface exif = new ExifInterface(fileName);
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
    long result = getExifDateTime(exif, TAG_DATETIME_ORIGINAL, formatter);
    CommonUtils.debug(TAG, "getExifDateTime: getting %1$s", TAG_DATETIME_ORIGINAL);
    if (result == -1) {
        CommonUtils.debug(TAG, "getExifDateTime: getting %1$s", TAG_DATETIME_DIGITIZED);
        result = getExifDateTime(exif, TAG_DATETIME_DIGITIZED, formatter);
    }
    if (result == -1) {
        CommonUtils.debug(TAG, "getExifDateTime: getting %1$s", TAG_DATETIME);
        result = getExifDateTime(exif, TAG_DATETIME, formatter);
    }
    return result;
}
Also used : ExifInterface(android.media.ExifInterface) SimpleDateFormat(java.text.SimpleDateFormat)

Example 74 with ExifInterface

use of android.media.ExifInterface in project TakePhoto by crazycodeboy.

the class ImageRotateUtil method getBitmapDegree.

/**
 * 读取图片的旋转的角度
 *
 * @param path 图片绝对路径
 * @return 图片的旋转角度
 */
private int getBitmapDegree(String path) {
    int degree = 0;
    try {
        // 从指定路径下读取图片,并获取其EXIF信息
        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)

Example 75 with ExifInterface

use of android.media.ExifInterface in project PhotoNoter by yydcdut.

the class SandBoxServicePresenterImpl method setExif.

// todo isMirror不好做啊!
private void setExif(PhotoNote photoNote, SandExif sandExif, String cameraId, boolean isMirror) throws IOException {
    ExifInterface exif = new ExifInterface(photoNote.getBigPhotoPathWithoutFile());
    if (cameraId.equals(Const.CAMERA_BACK)) {
        exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_ROTATE_90));
    } else {
        exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_ROTATE_270));
    }
    exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, sandExif.getLatitude());
    exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, sandExif.getLongitude());
    exif.setAttribute(ExifInterface.TAG_WHITE_BALANCE, String.valueOf(sandExif.getWhiteBalance()));
    exif.setAttribute(ExifInterface.TAG_FLASH, String.valueOf(sandExif.getFlash()));
    exif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, String.valueOf(sandExif.getImageLength()));
    exif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, String.valueOf(sandExif.getImageWidth()));
    exif.setAttribute(ExifInterface.TAG_MAKE, sandExif.getMake());
    exif.setAttribute(ExifInterface.TAG_MODEL, sandExif.getModel());
    exif.saveAttributes();
    ExifInterface exif2 = new ExifInterface(photoNote.getSmallPhotoPathWithoutFile());
    if (cameraId.equals(Const.CAMERA_BACK)) {
        exif2.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_ROTATE_90));
    } else {
        exif2.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_ROTATE_270));
    }
    exif2.saveAttributes();
}
Also used : ExifInterface(android.media.ExifInterface)

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