Search in sources :

Example 86 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 87 with ExifInterface

use of android.media.ExifInterface in project actor-platform by actorapp.

the class FileSource method loadMetadata.

@Override
protected ImageMetadata loadMetadata() throws ImageLoadException {
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    o.inTempStorage = WorkCache.BITMAP_TMP.get();
    BitmapFactory.decodeFile(fileName, o);
    if (o.outWidth == 0 || o.outHeight == 0) {
        throw new ImageLoadException("BitmapFactory.decodeFile: unable to load file");
    }
    int w = o.outWidth;
    int h = o.outHeight;
    ExifInterface exif = null;
    int orientationTag = 0;
    try {
        exif = new ExifInterface(fileName);
        String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
        if (exifOrientation != null) {
            if (exifOrientation.equals("5") || exifOrientation.equals("6") || exifOrientation.equals("7") || exifOrientation.equals("8")) {
                w = o.outHeight;
                h = o.outWidth;
            }
            orientationTag = Integer.parseInt(exifOrientation);
        }
    } catch (IOException e) {
    // e.printStackTrace();
    }
    ImageFormat format = ImageFormat.UNKNOWN;
    if ("image/jpeg".equals(o.outMimeType) || "image/jpg".equals(o.outMimeType)) {
        format = ImageFormat.JPEG;
    } else if ("image/gif".equals(o.outMimeType)) {
        format = ImageFormat.GIF;
    } else if ("image/bmp".equals(o.outMimeType)) {
        format = ImageFormat.BMP;
    } else if ("image/webp".equals(o.outMimeType)) {
        format = ImageFormat.WEBP;
    }
    return new ImageMetadata(w, h, orientationTag, format);
}
Also used : ExifInterface(android.media.ExifInterface) BitmapFactory(android.graphics.BitmapFactory) IOException(java.io.IOException)

Example 88 with ExifInterface

use of android.media.ExifInterface in project actor-platform by actorapp.

the class ImageHelper method loadOptimizedHQ.

public static Bitmap loadOptimizedHQ(String fileName) {
    int scale = getScaleFactor(getImageSize(fileName), MAX_PIXELS_HQ);
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inScaled = false;
    o.inSampleSize = scale;
    o.inPreferredConfig = Bitmap.Config.ARGB_8888;
    if (Build.VERSION.SDK_INT >= 10) {
        o.inPreferQualityOverSpeed = true;
    }
    if (Build.VERSION.SDK_INT >= 11) {
        o.inMutable = true;
    }
    if (!new File(fileName).exists()) {
        return null;
    }
    Bitmap res = BitmapFactory.decodeFile(fileName, o);
    if (res == null) {
        return null;
    }
    try {
        ExifInterface exif = new ExifInterface(fileName);
        String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
        int orientation = 0;
        if (exifOrientation != null) {
            orientation = Integer.parseInt(exifOrientation);
        }
        res = fixExif(res, orientation);
    } catch (IOException e) {
    // e.printStackTrace();
    }
    return res;
}
Also used : Bitmap(android.graphics.Bitmap) ExifInterface(android.media.ExifInterface) BitmapFactory(android.graphics.BitmapFactory) IOException(java.io.IOException) File(java.io.File) Paint(android.graphics.Paint)

Example 89 with ExifInterface

use of android.media.ExifInterface in project Android-Universal-Image-Loader by nostra13.

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

use of android.media.ExifInterface in project Luban by Curzibn.

the class Luban method getImageSpinAngle.

/**
     * obtain the image rotation angle
     *
     * @param path path of target image
     */
private int getImageSpinAngle(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)

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