Search in sources :

Example 41 with ExifInterface

use of android.media.ExifInterface in project BaseProject by fly803.

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 42 with ExifInterface

use of android.media.ExifInterface in project BaseProject by fly803.

the class BitmapUtils 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) Paint(android.graphics.Paint)

Example 43 with ExifInterface

use of android.media.ExifInterface in project OpenCamera by ageback.

the class ImageSaver method setExifFromData.

/**
 * As setExifFromFile, but can read the Exif tags directly from the jpeg data rather than a file.
 */
@RequiresApi(api = Build.VERSION_CODES.N)
private void setExifFromData(final Request request, byte[] data, File to_file) throws IOException {
    if (MyDebug.LOG) {
        Log.d(TAG, "setExifFromData");
        Log.d(TAG, "to_file: " + to_file);
    }
    InputStream inputStream = null;
    try {
        inputStream = new ByteArrayInputStream(data);
        ExifInterface exif = new ExifInterface(inputStream);
        ExifInterface exif_new = new ExifInterface(to_file.getAbsolutePath());
        setExif(request, exif, exif_new);
    } finally {
        if (inputStream != null) {
            inputStream.close();
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ExifInterface(android.media.ExifInterface) RequiresApi(android.support.annotation.RequiresApi)

Example 44 with ExifInterface

use of android.media.ExifInterface in project OpenCamera by ageback.

the class ImageSaver method updateExif.

/**
 * Makes various modifications to the saved image file, according to the preferences in request.
 */
private void updateExif(Request request, File picFile) throws IOException {
    if (MyDebug.LOG)
        Log.d(TAG, "updateExif: " + picFile);
    if (request.store_geo_direction || hasCustomExif(request.custom_tag_artist, request.custom_tag_copyright)) {
        if (MyDebug.LOG)
            Log.d(TAG, "add additional exif info");
        try {
            ExifInterface exif = new ExifInterface(picFile.getAbsolutePath());
            modifyExif(exif, request.type == Request.Type.JPEG, request.using_camera2, request.current_date, request.store_location, request.store_geo_direction, request.geo_direction, request.custom_tag_artist, request.custom_tag_copyright);
            exif.saveAttributes();
        } catch (NoClassDefFoundError exception) {
            // have had Google Play crashes from new ExifInterface() elsewhere for Galaxy Ace4 (vivalto3g), Galaxy S Duos3 (vivalto3gvn), so also catch here just in case
            if (MyDebug.LOG)
                Log.e(TAG, "exif orientation NoClassDefFoundError");
            exception.printStackTrace();
        }
    } else if (needGPSTimestampHack(request.type == Request.Type.JPEG, request.using_camera2, request.store_location)) {
        if (MyDebug.LOG)
            Log.d(TAG, "remove GPS timestamp hack");
        try {
            ExifInterface exif = new ExifInterface(picFile.getAbsolutePath());
            fixGPSTimestamp(exif, request.current_date);
            exif.saveAttributes();
        } catch (NoClassDefFoundError exception) {
            // have had Google Play crashes from new ExifInterface() elsewhere for Galaxy Ace4 (vivalto3g), Galaxy S Duos3 (vivalto3gvn), so also catch here just in case
            if (MyDebug.LOG)
                Log.e(TAG, "exif orientation NoClassDefFoundError");
            exception.printStackTrace();
        }
    } else {
        if (MyDebug.LOG)
            Log.d(TAG, "no exif data to update for: " + picFile);
    }
}
Also used : ExifInterface(android.media.ExifInterface)

Example 45 with ExifInterface

use of android.media.ExifInterface in project GomoTest by suReZj.

the class BitmapUtils method getOrientation.

// public static Bitmap loadImageByPath(final String imagePath, int reqWidth,
// int reqHeight) {
// File file = new File(imagePath);
// if (file.length() < MAX_SZIE) {
// return getSampledBitmap(imagePath, reqWidth, reqHeight);
// } else {// 压缩图片
// return getImageCompress(imagePath);
// }
// }
public static int getOrientation(final String imagePath) {
    int rotate = 0;
    try {
        File imageFile = new File(imagePath);
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch(orientation) {
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotate = 270;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotate = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotate = 90;
                break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rotate;
}
Also used : ExifInterface(android.media.ExifInterface) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

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