Search in sources :

Example 61 with ExifInterface

use of android.media.ExifInterface in project teaTime by ancfdy.

the class AppImageMgr method readPictureDegree.

/**
 * 判断图片旋转情况
 *
 * @param path
 * @return
 */
public static int readPictureDegree(String path) {
    int degree = 0;
    try {
        final ExifInterface exifInterface = new ExifInterface(path);
        final 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) SuppressLint(android.annotation.SuppressLint)

Example 62 with ExifInterface

use of android.media.ExifInterface in project Anki-Android by Ramblurr.

the class ExifUtil method rotateFromCamera.

public static Bitmap rotateFromCamera(File theFile, Bitmap bmp) {
    try {
        ExifInterface exif = new ExifInterface(theFile.getPath());
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        int angle = 0;
        if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
            angle = 90;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
            angle = 180;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
            angle = 270;
        }
        Matrix mat = new Matrix();
        mat.postRotate(angle);
        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), mat, true);
        return bmp;
    } catch (Exception e) {
        return bmp;
    }
}
Also used : Matrix(android.graphics.Matrix) ExifInterface(android.media.ExifInterface)

Example 63 with ExifInterface

use of android.media.ExifInterface in project SimpleCropView by IsseiAoki.

the class Utils method copyExifInfo.

/**
 * Copy EXIF info to new file
 *
 * =========================================
 *
 * NOTE: PNG cannot not have EXIF info.
 *
 * source: JPEG, save: JPEG
 * copies all EXIF data
 *
 * source: JPEG, save: PNG
 * saves no EXIF data
 *
 * source: PNG, save: JPEG
 * saves only width and height EXIF data
 *
 * source: PNG, save: PNG
 * saves no EXIF data
 *
 * =========================================
 */
public static void copyExifInfo(Context context, Uri sourceUri, Uri saveUri, int outputWidth, int outputHeight) {
    if (sourceUri == null || saveUri == null)
        return;
    try {
        File sourceFile = Utils.getFileFromUri(context, sourceUri);
        File saveFile = Utils.getFileFromUri(context, saveUri);
        if (sourceFile == null || saveFile == null) {
            return;
        }
        String sourcePath = sourceFile.getAbsolutePath();
        String savePath = saveFile.getAbsolutePath();
        ExifInterface sourceExif = new ExifInterface(sourcePath);
        List<String> tags = new ArrayList<>();
        tags.add(ExifInterface.TAG_DATETIME);
        tags.add(ExifInterface.TAG_FLASH);
        tags.add(ExifInterface.TAG_FOCAL_LENGTH);
        tags.add(ExifInterface.TAG_GPS_ALTITUDE);
        tags.add(ExifInterface.TAG_GPS_ALTITUDE_REF);
        tags.add(ExifInterface.TAG_GPS_DATESTAMP);
        tags.add(ExifInterface.TAG_GPS_LATITUDE);
        tags.add(ExifInterface.TAG_GPS_LATITUDE_REF);
        tags.add(ExifInterface.TAG_GPS_LONGITUDE);
        tags.add(ExifInterface.TAG_GPS_LONGITUDE_REF);
        tags.add(ExifInterface.TAG_GPS_PROCESSING_METHOD);
        tags.add(ExifInterface.TAG_GPS_TIMESTAMP);
        tags.add(ExifInterface.TAG_MAKE);
        tags.add(ExifInterface.TAG_MODEL);
        tags.add(ExifInterface.TAG_WHITE_BALANCE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            tags.add(ExifInterface.TAG_EXPOSURE_TIME);
            // noinspection deprecation
            tags.add(ExifInterface.TAG_APERTURE);
            // noinspection deprecation
            tags.add(ExifInterface.TAG_ISO);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            tags.add(ExifInterface.TAG_DATETIME_DIGITIZED);
            tags.add(ExifInterface.TAG_SUBSEC_TIME);
            // noinspection deprecation
            tags.add(ExifInterface.TAG_SUBSEC_TIME_DIG);
            // noinspection deprecation
            tags.add(ExifInterface.TAG_SUBSEC_TIME_ORIG);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            tags.add(ExifInterface.TAG_F_NUMBER);
            tags.add(ExifInterface.TAG_ISO_SPEED_RATINGS);
            tags.add(ExifInterface.TAG_SUBSEC_TIME_DIGITIZED);
            tags.add(ExifInterface.TAG_SUBSEC_TIME_ORIGINAL);
        }
        ExifInterface saveExif = new ExifInterface(savePath);
        String value;
        for (String tag : tags) {
            value = sourceExif.getAttribute(tag);
            if (!TextUtils.isEmpty(value)) {
                saveExif.setAttribute(tag, value);
            }
        }
        saveExif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, String.valueOf(outputWidth));
        saveExif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, String.valueOf(outputHeight));
        saveExif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_UNDEFINED));
        saveExif.saveAttributes();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ExifInterface(android.media.ExifInterface) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 64 with ExifInterface

use of android.media.ExifInterface in project boxing by Bilibili.

the class BoxingExifHelper method getRotateDegree.

static int getRotateDegree(String path) {
    int result = 0;
    try {
        ExifInterface exif = new ExifInterface(path);
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch(orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                result = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                result = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                result = 270;
                break;
        }
    } catch (IOException ignore) {
        return 0;
    }
    return result;
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException)

Example 65 with ExifInterface

use of android.media.ExifInterface in project android-crop by jdamcd.

the class CropUtil method copyExifRotation.

public static boolean copyExifRotation(File sourceFile, File destFile) {
    if (sourceFile == null || destFile == null)
        return false;
    try {
        ExifInterface exifSource = new ExifInterface(sourceFile.getAbsolutePath());
        ExifInterface exifDest = new ExifInterface(destFile.getAbsolutePath());
        exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, exifSource.getAttribute(ExifInterface.TAG_ORIENTATION));
        exifDest.saveAttributes();
        return true;
    } catch (IOException e) {
        Log.e("Error copying Exif data", e);
        return false;
    }
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException)

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