Example usage for android.media ExifInterface ORIENTATION_ROTATE_180

List of usage examples for android.media ExifInterface ORIENTATION_ROTATE_180

Introduction

In this page you can find the example usage for android.media ExifInterface ORIENTATION_ROTATE_180.

Prototype

int ORIENTATION_ROTATE_180

To view the source code for android.media ExifInterface ORIENTATION_ROTATE_180.

Click Source Link

Usage

From source file:com.m2dl.mini_projet.mini_projet_android.MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE:
        if (resultCode == Activity.RESULT_OK) {
            Uri selectedImage = imageUri;
            getContentResolver().notifyChange(selectedImage, null);

            ContentResolver cr = getContentResolver();
            try {
                myBitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImage);
                myBitmap = BitmapUtil.resize(myBitmap);
                imageFilePath = imageUri.getPath();
                ExifInterface exif = new ExifInterface(imageFilePath);
                int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                        ExifInterface.ORIENTATION_NORMAL);
                switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    myBitmap = BitmapUtil.rotateImage(myBitmap, 90);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    myBitmap = BitmapUtil.rotateImage(myBitmap, 180);
                    break;
                }//from w  w  w.jav  a 2 s.c o m
                String dialogTitle;
                String dialogMessage;
                if (!isGPSOn) {
                    dialogTitle = "Golocalisation GPS...";
                    dialogMessage = "Veuillez activer votre GPS puis patienter pendant la golocalisation";
                } else {
                    dialogTitle = "Golocalisation GPS...";
                    dialogMessage = "Veuillez patienter pendant la golocalisation";
                }
                final ProgressDialog progDialog = ProgressDialog.show(MainActivity.this, dialogTitle,
                        dialogMessage, true);
                new Thread() {
                    public void run() {
                        try {
                            while (coordLat.equals(0.0d) && coordLong.equals(0.0d))
                                ;
                            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                            Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
                            if (prev != null) {
                                ft.remove(prev);
                            }
                            ft.addToBackStack(null);
                            DialogFragment newFragment = PhotoDialogFragment.newInstance(myBitmap, coordLat,
                                    coordLong, imageFilePath);
                            newFragment.show(ft, "dialog");
                        } catch (Exception e) {
                            Log.e(TAG, e.getMessage());
                        }
                        progDialog.dismiss();
                    }
                }.start();
            } catch (Exception e) {
                Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();
                Log.e("Camera", e.toString());
            }
        }
    }
}

From source file:com.google.android.gms.samples.vision.face.photo.PhotoViewerActivity.java

public Bitmap grabImage() {
    this.getContentResolver().notifyChange(photoURI, null);
    ContentResolver cr = this.getContentResolver();
    Bitmap bitmap;// ww  w .  jav a 2 s. co m
    try {
        bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, photoURI);

        ExifInterface ei = new ExifInterface(mCurrentPhotoPath);
        int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_UNDEFINED);

        switch (orientation) {

        case ExifInterface.ORIENTATION_ROTATE_90:
            bitmap = rotateImage(bitmap, 90);
            break;

        case ExifInterface.ORIENTATION_ROTATE_180:
            bitmap = rotateImage(bitmap, 180);
            break;

        case ExifInterface.ORIENTATION_ROTATE_270:
            bitmap = rotateImage(bitmap, 270);
            break;

        case ExifInterface.ORIENTATION_NORMAL:

        default:
            break;
        }
        return bitmap;
    } catch (Exception e) {
        Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();
        Log.d(TAG, "Failed to load", e);
        return null;
    }
}

From source file:Main.java

/**
 * get image orientation rotate degree/*from   w w w .j av a  2  s .c  o m*/
 *
 * @param filepath
 * @return
 */
public static int getExifOrientation(String filepath) {
    int degree = 0;
    ExifInterface exif = null;
    try {
        exif = new ExifInterface(filepath);
    } catch (IOException ex) {
        Log.d(TAG, "cannot read exif" + ex);
    }
    if (exif != null) {
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
        if (orientation != -1) {
            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;
            }
        }
    }
    return degree;
}

From source file:com.allen.mediautil.ImageTakerHelper.java

/**
 * ?/*www .ja  va 2  s .  c o m*/
 *
 * @param path ?
 * @return degree
 */
private static int readPictureDegree(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;// SUPPRESS CHECKSTYLE
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            degree = 180;// SUPPRESS CHECKSTYLE
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            degree = 270;// SUPPRESS CHECKSTYLE
            break;
        default:
            break;
        }
    } catch (IOException e) {
        Log.e("readPictureDegree", "readPictureDegree failed", e);
    }
    return degree;
}

From source file:com.yanzhenjie.album.task.LocalImageLoader.java

/**
 * Read the rotation angle of the picture file.
 *
 * @param path image path./*from  w w  w.ja  va  2s .  c  o  m*/
 * @return one of 0, 90, 180, 270.
 */
public static int readDegree(String path) {
    try {
        ExifInterface exifInterface = new ExifInterface(path);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            return 90;
        case ExifInterface.ORIENTATION_ROTATE_180:
            return 180;
        case ExifInterface.ORIENTATION_ROTATE_270:
            return 270;
        default:
            return 0;
        }
    } catch (Exception e) {
        return 0;
    }
}

From source file:org.planetmono.dcuploader.ActivityUploader.java

public int queryExifOrientation(String path) {
    int orientation = 0;

    if (exifConstructor == null) {
        try {//from  w w  w  .  j  a v  a2  s .  c o  m
            exifConstructor = ExifInterface.class.getConstructor(new Class[] { String.class });
            exifGetAttributeInt = ExifInterface.class.getMethod("getAttributeInt",
                    new Class[] { String.class, int.class });
        } catch (NoSuchMethodException e) {
            return 0;
        }
    }

    Integer o = 0;
    try {
        Object obj = exifConstructor.newInstance(new Object[] { path });
        o = (Integer) exifGetAttributeInt.invoke(obj, ExifInterface.TAG_ORIENTATION, new Integer(0));
    } catch (Exception e) {
        return 0;
    }

    Log.d(Application.TAG, "orientation " + o);

    switch (o) {
    case ExifInterface.ORIENTATION_ROTATE_90:
        orientation = 90;
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        orientation = 180;
        break;
    case ExifInterface.ORIENTATION_ROTATE_270:
        orientation = 270;
    }

    return orientation;
}

From source file:com.silentcircle.common.util.ViewUtil.java

/**
 * Finds JPEG image rotation flags from exif and returns matrix to be used to rotate image.
 *
 * @param fileName JPEG image file name.
 *
 * @return Matrix to use in image rotate transformation or null if parsing failed.
 *//*  w  ww  .  ja v a2s .  c om*/
public static Matrix getRotationMatrixFromExif(final String fileName) {
    Matrix matrix = null;
    try {
        ExifInterface exif = new ExifInterface(fileName);
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        int rotate = 0;

        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            rotate = ROTATE_90;
            break;

        case ExifInterface.ORIENTATION_ROTATE_180:
            rotate = ROTATE_180;
            break;

        case ExifInterface.ORIENTATION_ROTATE_270:
            rotate = ROTATE_270;
            break;
        }

        if (rotate != 0) {
            matrix = new Matrix();
            matrix.preRotate(rotate);
        }
    } catch (IOException e) {
        Log.i(TAG, "Failed to determine image flags from file " + fileName);
    }
    return matrix;
}

From source file:com.almalence.opencam.PluginManager.java

@Override
protected void createPlugins() {
    pluginList = new Hashtable<String, Plugin>();
    processingPluginList = new HashMap<Long, Plugin>();

    sharedMemory = new Hashtable<String, String>();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        createRAWCaptureResultHashtable();

    activeVF = new ArrayList<String>();
    // activeFilter = new ArrayList<String>();

    listVF = new ArrayList<Plugin>();
    listCapture = new ArrayList<Plugin>();
    listProcessing = new ArrayList<Plugin>();
    // listFilter = new ArrayList<Plugin>();
    listExport = new ArrayList<Plugin>();

    // init plugins and add to pluginList
    /*//ww  w .j  av a  2  s . co m
     * Insert any new plugin below (create and add to list of concrete type)
     */

    // VF
    AeAwLockVFPlugin aeawlockVFPlugin = new AeAwLockVFPlugin();
    pluginList.put(aeawlockVFPlugin.getID(), aeawlockVFPlugin);
    listVF.add(aeawlockVFPlugin);

    HistogramVFPlugin histgramVFPlugin = new HistogramVFPlugin();
    pluginList.put(histgramVFPlugin.getID(), histgramVFPlugin);
    listVF.add(histgramVFPlugin);

    BarcodeScannerVFPlugin barcodeScannerVFPlugin = new BarcodeScannerVFPlugin();
    pluginList.put(barcodeScannerVFPlugin.getID(), barcodeScannerVFPlugin);
    listVF.add(barcodeScannerVFPlugin);

    GyroVFPlugin gyroVFPlugin = new GyroVFPlugin();
    pluginList.put(gyroVFPlugin.getID(), gyroVFPlugin);
    listVF.add(gyroVFPlugin);

    ZoomVFPlugin zoomVFPlugin = new ZoomVFPlugin();
    pluginList.put(zoomVFPlugin.getID(), zoomVFPlugin);
    listVF.add(zoomVFPlugin);

    GridVFPlugin gridVFPlugin = new GridVFPlugin();
    pluginList.put(gridVFPlugin.getID(), gridVFPlugin);
    listVF.add(gridVFPlugin);

    FocusVFPlugin focusVFPlugin = new FocusVFPlugin();
    pluginList.put(focusVFPlugin.getID(), focusVFPlugin);
    listVF.add(focusVFPlugin);

    InfosetVFPlugin infosetVFPlugin = new InfosetVFPlugin();
    pluginList.put(infosetVFPlugin.getID(), infosetVFPlugin);
    listVF.add(infosetVFPlugin);

    // Capture
    CapturePlugin testCapturePlugin = new CapturePlugin();
    pluginList.put(testCapturePlugin.getID(), testCapturePlugin);
    listCapture.add(testCapturePlugin);

    ExpoBracketingCapturePlugin expoBracketingCapturePlugin = new ExpoBracketingCapturePlugin();
    pluginList.put(expoBracketingCapturePlugin.getID(), expoBracketingCapturePlugin);
    listCapture.add(expoBracketingCapturePlugin);

    NightCapturePlugin nightCapturePlugin = new NightCapturePlugin();
    pluginList.put(nightCapturePlugin.getID(), nightCapturePlugin);
    listCapture.add(nightCapturePlugin);

    BurstCapturePlugin burstCapturePlugin = new BurstCapturePlugin();
    pluginList.put(burstCapturePlugin.getID(), burstCapturePlugin);
    listCapture.add(burstCapturePlugin);

    BestShotCapturePlugin bestShotCapturePlugin = new BestShotCapturePlugin();
    pluginList.put(bestShotCapturePlugin.getID(), bestShotCapturePlugin);
    listCapture.add(bestShotCapturePlugin);

    MultiShotCapturePlugin multiShotCapturePlugin = new MultiShotCapturePlugin();
    pluginList.put(multiShotCapturePlugin.getID(), multiShotCapturePlugin);
    listCapture.add(multiShotCapturePlugin);

    VideoCapturePlugin videoCapturePlugin = new VideoCapturePlugin();
    pluginList.put(videoCapturePlugin.getID(), videoCapturePlugin);
    listCapture.add(videoCapturePlugin);

    PreshotCapturePlugin backInTimeCapturePlugin = new PreshotCapturePlugin();
    pluginList.put(backInTimeCapturePlugin.getID(), backInTimeCapturePlugin);
    listCapture.add(backInTimeCapturePlugin);

    PanoramaAugmentedCapturePlugin panoramaAugmentedCapturePlugin = new PanoramaAugmentedCapturePlugin();
    pluginList.put(panoramaAugmentedCapturePlugin.getID(), panoramaAugmentedCapturePlugin);
    listCapture.add(panoramaAugmentedCapturePlugin);

    PreshotProcessingPlugin backInTimeProcessingPlugin = new PreshotProcessingPlugin();
    pluginList.put(backInTimeProcessingPlugin.getID(), backInTimeProcessingPlugin);
    listCapture.add(backInTimeProcessingPlugin);

    // Processing
    SimpleProcessingPlugin simpleProcessingPlugin = new SimpleProcessingPlugin();
    pluginList.put(simpleProcessingPlugin.getID(), simpleProcessingPlugin);
    listProcessing.add(simpleProcessingPlugin);

    NightProcessingPlugin nightProcessingPlugin = new NightProcessingPlugin();
    pluginList.put(nightProcessingPlugin.getID(), nightProcessingPlugin);
    listProcessing.add(nightProcessingPlugin);

    HDRProcessingPlugin hdrProcessingPlugin = new HDRProcessingPlugin();
    pluginList.put(hdrProcessingPlugin.getID(), hdrProcessingPlugin);
    listProcessing.add(hdrProcessingPlugin);

    MultiShotProcessingPlugin multiShotProcessingPlugin = new MultiShotProcessingPlugin();
    pluginList.put(multiShotProcessingPlugin.getID(), multiShotProcessingPlugin);
    listProcessing.add(multiShotProcessingPlugin);

    PanoramaProcessingPlugin panoramaProcessingPlugin = new PanoramaProcessingPlugin();
    pluginList.put(panoramaProcessingPlugin.getID(), panoramaProcessingPlugin);
    listProcessing.add(panoramaProcessingPlugin);

    BestshotProcessingPlugin bestshotProcessingPlugin = new BestshotProcessingPlugin();
    pluginList.put(bestshotProcessingPlugin.getID(), bestshotProcessingPlugin);
    listProcessing.add(bestshotProcessingPlugin);

    // Filter

    // Export
    ExportPlugin testExportPlugin = new ExportPlugin();
    pluginList.put(testExportPlugin.getID(), testExportPlugin);
    listExport.add(testExportPlugin);

    // parsing configuration file to setup modes
    parseConfig();

    exifOrientationMap = new HashMap<Integer, Integer>() {
        {
            put(0, ExifInterface.ORIENTATION_NORMAL);
            put(90, ExifInterface.ORIENTATION_ROTATE_90);
            put(180, ExifInterface.ORIENTATION_ROTATE_180);
            put(270, ExifInterface.ORIENTATION_ROTATE_270);
        }
    };
}

From source file:com.spoiledmilk.ibikecph.util.Util.java

public static Bitmap bmpDecodeFile(File f, int width_limit, int height_limit, long max_size,
        boolean max_dimensions) {
    if (f == null) {
        return null;
    }//from  w  w w .ja  v  a 2  s. c o m

    LOG.d("bmpDecodeFile(" + f.getAbsolutePath() + "," + width_limit + "," + height_limit + "," + max_size + ","
            + max_dimensions + ")");

    Bitmap bmp = null;
    boolean shouldReturn = false;

    FileInputStream fin = null;
    int orientation = ExifInterface.ORIENTATION_NORMAL;
    try {
        // Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        fin = new FileInputStream(f);
        BitmapFactory.decodeStream(fin, null, o);
        try {
            fin.close();
            fin = null;
        } catch (IOException e) {
        }

        // Find the correct scale value. It should be the power of 2.
        int scale = 1;
        if (width_limit != -1 && height_limit != -1) {
            if (max_dimensions) {
                while (o.outWidth / scale > width_limit || o.outHeight / scale > height_limit)
                    scale *= 2;
            } else {
                while (o.outWidth / scale / 2 >= width_limit && o.outHeight / scale / 2 >= height_limit)
                    scale *= 2;
            }
        } else if (max_size != -1)
            while ((o.outWidth * o.outHeight) / (scale * scale) > max_size)
                scale *= 2;

        // Decode with inSampleSize
        o = null;
        if (scale > 1) {
            o = new BitmapFactory.Options();
            o.inSampleSize = scale;
        }
        fin = new FileInputStream(f);
        try {
            bmp = BitmapFactory.decodeStream(fin, null, o);
        } catch (OutOfMemoryError e) {
            // Try to recover from out of memory error - but keep in mind
            // that behavior after this error is
            // undefined,
            // for example more out of memory errors might appear in catch
            // block.
            if (bmp != null)
                bmp.recycle();
            bmp = null;
            System.gc();
            LOG.e("Util.bmpDecodeFile() OutOfMemoryError in decodeStream()! Trying to recover...");
        }

        if (bmp != null) {
            LOG.d("resulting bitmap width : " + bmp.getWidth() + " height : " + bmp.getHeight() + " size : "
                    + (bmp.getRowBytes() * bmp.getHeight()));

            ExifInterface exif = new ExifInterface(f.getPath());
            orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        }
    } catch (FileNotFoundException e) {
        shouldReturn = true;
    } catch (IOException e) {
        shouldReturn = true; // bitmap is still valid here, just can't be
        // rotated
    } finally {
        if (fin != null)
            try {
                fin.close();
            } catch (IOException e) {
            }
    }

    if (shouldReturn || bmp == null)
        return bmp;

    float rotate = 0;
    switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
        rotate = 90;
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        rotate = 180;
        break;
    case ExifInterface.ORIENTATION_ROTATE_270:
        rotate = 270;
        break;
    }
    if (rotate > 0) {
        Matrix matrix = new Matrix();
        matrix.postRotate(rotate);
        Bitmap bmpRot = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
        matrix = null;
        bmp.recycle();
        bmp = null;
        // System.gc();
        return bmpRot;
    }

    return bmp;
}

From source file:com.example.photoremark.MainActivity.java

/**
 * ?exif?/*from w ww. j  a  v a 2 s  .co m*/
 *
 * @param path 
 * @return
 */
public int getPictureDegree(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;
}