Search in sources :

Example 1 with ExifInterface

use of android.media.ExifInterface in project rainbow by juankysoriano.

the class RainbowBitmapUtils method getRotation.

public static int getRotation(String filename) {
    ExifInterface exif;
    int exifOrientation = ExifInterface.ORIENTATION_NORMAL;
    int cameraId = -1;
    try {
        exif = new ExifInterface(filename);
        exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        cameraId = exif.getAttribute("UserComment") != null ? Integer.valueOf(exif.getAttribute("UserComment")) : -1;
    } catch (Exception e) {
        cameraId = -1;
        exifOrientation = ExifInterface.ORIENTATION_NORMAL;
    } finally {
        if (exifOrientation >= 0) {
            return exifOrientationToDegrees(exifOrientation, cameraId);
        }
    }
    return 0;
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException)

Example 2 with ExifInterface

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

the class ImageHelper method getImageSize.

public static BitmapSize getImageSize(String fileName) {
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(fileName, o);
    if (o.outWidth == 0 || o.outHeight == 0) {
        return null;
    }
    int w = o.outWidth;
    int h = o.outHeight;
    try {
        ExifInterface 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;
            }
        }
    } catch (IOException e) {
    // e.printStackTrace();
    }
    return new BitmapSize(w, h);
}
Also used : ExifInterface(android.media.ExifInterface) BitmapFactory(android.graphics.BitmapFactory) IOException(java.io.IOException) Paint(android.graphics.Paint)

Example 3 with ExifInterface

use of android.media.ExifInterface in project material-camera by afollestad.

the class ImageUtil method getExifDegreesFromJpeg.

private static int getExifDegreesFromJpeg(String inputFile) {
    try {
        final ExifInterface exif = new ExifInterface(inputFile);
        final int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {
            return 90;
        } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {
            return 180;
        } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {
            return 270;
        }
    } catch (IOException e) {
        Log.e("exif", "Error when trying to get exif data from : " + inputFile, e);
    }
    return 0;
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException)

Example 4 with ExifInterface

use of android.media.ExifInterface in project android_frameworks_base by ResurrectionRemix.

the class CameraTestUtils method verifyJpegKeys.

/**
     * Verify the JPEG EXIF and JPEG related keys in a capture result are expected.
     * - Capture request get values are same as were set.
     * - capture result's exif data is the same as was set by
     *   the capture request.
     * - new tags in the result set by the camera service are
     *   present and semantically correct.
     *
     * @param image The output JPEG image to verify.
     * @param captureResult The capture result to verify.
     * @param expectedSize The expected JPEG size.
     * @param expectedThumbnailSize The expected thumbnail size.
     * @param expectedExifData The expected EXIF data
     * @param staticInfo The static metadata for the camera device.
     * @param jpegFilename The filename to dump the jpeg to.
     * @param collector The camera error collector to collect errors.
     */
public static void verifyJpegKeys(Image image, CaptureResult captureResult, Size expectedSize, Size expectedThumbnailSize, ExifTestData expectedExifData, StaticMetadata staticInfo, CameraErrorCollector collector) throws Exception {
    basicValidateJpegImage(image, expectedSize);
    byte[] jpegBuffer = getDataFromImage(image);
    // Have to dump into a file to be able to use ExifInterface
    String jpegFilename = DEBUG_FILE_NAME_BASE + "/verifyJpegKeys.jpeg";
    dumpFile(jpegFilename, jpegBuffer);
    ExifInterface exif = new ExifInterface(jpegFilename);
    if (expectedThumbnailSize.equals(new Size(0, 0))) {
        collector.expectTrue("Jpeg shouldn't have thumbnail when thumbnail size is (0, 0)", !exif.hasThumbnail());
    } else {
        collector.expectTrue("Jpeg must have thumbnail for thumbnail size " + expectedThumbnailSize, exif.hasThumbnail());
    }
    // Validate capture result vs. request
    Size resultThumbnailSize = captureResult.get(CaptureResult.JPEG_THUMBNAIL_SIZE);
    int orientationTested = expectedExifData.jpegOrientation;
    // Legacy shim always doesn't rotate thumbnail size
    if ((orientationTested == 90 || orientationTested == 270) && staticInfo.isHardwareLevelLimitedOrBetter()) {
        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, /*defaultValue*/
        -1);
        if (exifOrientation == ExifInterface.ORIENTATION_UNDEFINED) {
            // Device physically rotated image+thumbnail data
            // Expect thumbnail size to be also rotated
            resultThumbnailSize = new Size(resultThumbnailSize.getHeight(), resultThumbnailSize.getWidth());
        }
    }
    collector.expectEquals("JPEG thumbnail size result and request should match", expectedThumbnailSize, resultThumbnailSize);
    if (collector.expectKeyValueNotNull(captureResult, CaptureResult.JPEG_GPS_LOCATION) != null) {
        collector.expectTrue("GPS location result and request should match.", areGpsFieldsEqual(expectedExifData.gpsLocation, captureResult.get(CaptureResult.JPEG_GPS_LOCATION)));
    }
    collector.expectEquals("JPEG orientation result and request should match", expectedExifData.jpegOrientation, captureResult.get(CaptureResult.JPEG_ORIENTATION));
    collector.expectEquals("JPEG quality result and request should match", expectedExifData.jpegQuality, captureResult.get(CaptureResult.JPEG_QUALITY));
    collector.expectEquals("JPEG thumbnail quality result and request should match", expectedExifData.thumbnailQuality, captureResult.get(CaptureResult.JPEG_THUMBNAIL_QUALITY));
    // Validate other exif tags for all non-legacy devices
    if (!staticInfo.isHardwareLevelLegacy()) {
        verifyJpegExifExtraTags(exif, expectedSize, captureResult, staticInfo, collector);
    }
}
Also used : Size(android.util.Size) ExifInterface(android.media.ExifInterface)

Example 5 with ExifInterface

use of android.media.ExifInterface in project android_frameworks_base by ResurrectionRemix.

the class ExifInterfaceTest method testExifInterfaceCommon.

private void testExifInterfaceCommon(File imageFile, ExpectedValue expectedValue) throws IOException {
    String verboseTag = imageFile.getName();
    // Creates via path.
    ExifInterface exifInterface = new ExifInterface(imageFile.getAbsolutePath());
    compareWithExpectedValue(exifInterface, expectedValue, verboseTag);
    // Creates from an asset file.
    InputStream in = null;
    try {
        in = mContext.getAssets().open(imageFile.getName());
        exifInterface = new ExifInterface(in);
        compareWithExpectedValue(exifInterface, expectedValue, verboseTag);
    } finally {
        IoUtils.closeQuietly(in);
    }
    // Creates via InputStream.
    in = null;
    try {
        in = new BufferedInputStream(new FileInputStream(imageFile.getAbsolutePath()));
        exifInterface = new ExifInterface(in);
        compareWithExpectedValue(exifInterface, expectedValue, verboseTag);
    } finally {
        IoUtils.closeQuietly(in);
    }
    // Creates via FileDescriptor.
    FileDescriptor fd = null;
    try {
        fd = Os.open(imageFile.getAbsolutePath(), OsConstants.O_RDONLY, 0600);
        exifInterface = new ExifInterface(fd);
        compareWithExpectedValue(exifInterface, expectedValue, verboseTag);
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    } finally {
        IoUtils.closeQuietly(fd);
    }
}
Also used : ErrnoException(android.system.ErrnoException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ExifInterface(android.media.ExifInterface) FileInputStream(java.io.FileInputStream) FileDescriptor(java.io.FileDescriptor)

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