Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.Bitmap;

import android.graphics.Matrix;

import android.media.ExifInterface;
import android.net.Uri;

import java.io.IOException;

public class Main {
    public static Bitmap fixBitmapOrientation(Uri uri, Bitmap bmp) throws IOException {
        ExifInterface ei = new ExifInterface(uri.getPath());
        int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            return rotateBitmap(bmp, 90);
        case ExifInterface.ORIENTATION_ROTATE_180:
            return rotateBitmap(bmp, 180);
        case ExifInterface.ORIENTATION_ROTATE_270:
            return rotateBitmap(bmp, 270);
        }

        return bmp;
    }

    public static Bitmap rotateBitmap(Bitmap source, float angle) {
        Matrix matrix = new Matrix();
        matrix.postRotate(angle);

        return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
    }
}