Example usage for android.media ExifInterface TAG_ORIENTATION

List of usage examples for android.media ExifInterface TAG_ORIENTATION

Introduction

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

Prototype

String TAG_ORIENTATION

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

Click Source Link

Document

Type is int.

Usage

From source file:com.cpjd.roblu.ui.images.ImageGalleryActivity.java

/**
 * Receives the picture that was taken by the user
 * @param requestCode the request code of the child activity
 * @param resultCode the result code of the child activity
 * @param data the picture that was taken
 *///from  w  w w  .  j a v a 2s  .  c  om
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == Constants.GENERAL && resultCode == FragmentActivity.RESULT_OK) {
        // fetch file from storage
        Bitmap bitmap = BitmapFactory.decodeFile(tempPictureFile.getPath());
        // fix rotation
        try {
            ExifInterface ei = new ExifInterface(tempPictureFile.getPath());
            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;
            default:
                break;
            }
        } catch (IOException e) {
            Log.d("RBS", "Failed to remove EXIF rotation data from the picture.");
        }

        /*
         * Convert the image into a byte[] and save it to the gallery
         */

        // Convert the bitmap to a byte array
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 30, stream);
        byte[] array = stream.toByteArray();

        int newID = new IO(getApplicationContext()).savePicture(eventID, array);

        // Add the image to the current array
        if (IMAGES == null)
            IMAGES = new ArrayList<>();
        IMAGES.add(array);

        // save the ID to the gallery
        for (int i = 0; i < TeamViewer.team.getTabs().get(rTabIndex).getMetrics().size(); i++) {
            if (TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i).getID() == galleryID) {
                if (((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i))
                        .getPictureIDs() == null) {
                    ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i))
                            .setPictureIDs(new ArrayList<Integer>());
                }
                ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).getPictureIDs()
                        .add(newID);
                break;
            }
        }
        TeamViewer.team.setLastEdit(System.currentTimeMillis());

        new IO(getApplicationContext()).saveTeam(eventID, TeamViewer.team);
        imageGalleryAdapter.notifyDataSetChanged();
    }
    /*
     * User edited an image
     */
    else if (resultCode == Constants.IMAGE_EDITED) {
        TeamViewer.team.setLastEdit(System.currentTimeMillis());

        /*
         * Update the image in the gallery
         */
        for (int i = 0; i < TeamViewer.team.getTabs().get(rTabIndex).getMetrics().size(); i++) {
            if (TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i).getID() == galleryID) {
                if (((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i))
                        .getPictureIDs() == null) {
                    ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i))
                            .setPictureIDs(new ArrayList<Integer>());
                }
                ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).getPictureIDs()
                        .add(new IO(getApplicationContext()).savePicture(eventID,
                                IMAGES.get(data.getIntExtra("position", 0))));
                break;
            }
        }

        new IO(getApplicationContext()).saveTeam(eventID, TeamViewer.team);
        imageGalleryAdapter.notifyDataSetChanged();
    }
    /*
     * User deleted an image
     */
    else if (resultCode == Constants.IMAGE_DELETED) {
        // Remove the image from the gallery ID list
        for (int i = 0; i < TeamViewer.team.getTabs().get(rTabIndex).getMetrics().size(); i++) {
            if (TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i).getID() == galleryID) {
                int pictureID = ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i))
                        .getPictureIDs().remove(data.getIntExtra("position", 0));
                // delete from file system
                new IO(getApplicationContext()).deletePicture(eventID, pictureID);
                break;
            }
        }

        IMAGES.remove(data.getIntExtra("position", 0));
        imageGalleryAdapter.notifyDataSetChanged();

        TeamViewer.team.setLastEdit(System.currentTimeMillis());

        new IO(getApplicationContext()).saveTeam(eventID, TeamViewer.team);
    }
}

From source file:com.netcompss.ffmpeg4android_client.BaseVideo.java

@SuppressWarnings("unused")
private String reporteds(String path) {

    ExifInterface exif = null;// w ww.j a va2 s.  c  om
    try {
        exif = new ExifInterface(path);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    Matrix matrix = new Matrix();
    if (orientation == 6) {
        matrix.postRotate(90);
    } else if (orientation == 3) {
        matrix.postRotate(180);
    } else if (orientation == 8) {
        matrix.postRotate(270);
    }

    if (path != null) {

        if (path.contains("http")) {
            try {
                URL url = new URL(path);
                HttpGet httpRequest = null;

                httpRequest = new HttpGet(url.toURI());

                HttpClient httpclient = new DefaultHttpClient();
                HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);

                HttpEntity entity = response.getEntity();
                BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
                InputStream input = bufHttpEntity.getContent();

                Bitmap bitmap = BitmapFactory.decodeStream(input);
                input.close();
                return getPath(bitmap);
            } catch (MalformedURLException e) {
                Log.e("ImageActivity", "bad url", e);
            } catch (Exception e) {
                Log.e("ImageActivity", "io error", e);
            }
        } else {

            Options options = new Options();
            options.inSampleSize = 2;
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeResource(context.getResources(), srcBgId, options);
            options.inJustDecodeBounds = false;
            options.inSampleSize = calculateInSampleSize(options, w, h);
            Bitmap unbgbtmp = BitmapFactory.decodeResource(context.getResources(), srcBgId, options);
            Bitmap unrlbtmp = ScalingUtilities.decodeFile(path, w, h, ScalingLogic.FIT);
            unrlbtmp.recycle();
            Bitmap rlbtmp = null;
            if (unrlbtmp != null) {
                rlbtmp = ScalingUtilities.createScaledBitmap(unrlbtmp, w, h, ScalingLogic.FIT);
            }
            if (unbgbtmp != null && rlbtmp != null) {
                Bitmap bgbtmp = ScalingUtilities.createScaledBitmap(unbgbtmp, w, h, ScalingLogic.FIT);
                Bitmap newscaledBitmap = ProcessingBitmapTwo(bgbtmp, rlbtmp);
                unbgbtmp.recycle();
                return getPath(newscaledBitmap);
            }
        }
    }
    return path;

}

From source file:com.daiv.android.twitter.services.SendTweet.java

public Bitmap getBitmapToSend(Uri uri, Context context) throws IOException {
    InputStream input = context.getContentResolver().openInputStream(uri);
    int reqWidth = 750;
    int reqHeight = 750;

    byte[] byteArr = new byte[0];
    byte[] buffer = new byte[1024];
    int len;/*  w  w  w  . ja va  2 s  .  c  o  m*/
    int count = 0;

    try {
        while ((len = input.read(buffer)) > -1) {
            if (len != 0) {
                if (count + len > byteArr.length) {
                    byte[] newbuf = new byte[(count + len) * 2];
                    System.arraycopy(byteArr, 0, newbuf, 0, count);
                    byteArr = newbuf;
                }

                System.arraycopy(buffer, 0, byteArr, count, len);
                count += len;
            }
        }

        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeByteArray(byteArr, 0, count, options);

        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
        options.inPurgeable = true;
        options.inInputShareable = true;
        options.inJustDecodeBounds = false;
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;

        Bitmap b = BitmapFactory.decodeByteArray(byteArr, 0, count, options);

        ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context));
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_UNDEFINED);

        return rotateBitmap(b, orientation);

    } catch (Exception e) {
        e.printStackTrace();

        return null;
    }
}

From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java

private static Bitmap rotate(String path, Bitmap bm) {
    if (bm == null) {
        return null;
    }/*from www  .j a  v a  2  s  .  c  o  m*/
    Bitmap result = bm;
    int ori = ExifInterface.ORIENTATION_NORMAL;
    try {
        ExifInterface ei = new ExifInterface(path);
        ori = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    } catch (Exception e) {
        //simply fallback to normal orientation
        AQUtility.debug(e);
    }
    if (ori > 0) {
        Matrix matrix = getRotateMatrix(ori);
        result = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
        AQUtility.debug("before", bm.getWidth() + ":" + bm.getHeight());
        AQUtility.debug("after", result.getWidth() + ":" + result.getHeight());
        if (bm != result) {
            bm.recycle();
        }
    }
    return result;
}

From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java

private static Bitmap rotate(String path, Bitmap bm) {

    if (bm == null)
        return null;

    Bitmap result = bm;/*from w  ww .java 2  s  .  com*/

    int ori = ExifInterface.ORIENTATION_NORMAL;

    try {
        ExifInterface ei = new ExifInterface(path);
        ori = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    } catch (Exception e) {
        //simply fallback to normal orientation
        AQUtility.debug(e);
    }

    if (ori > 0) {

        Matrix matrix = getRotateMatrix(ori);
        result = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);

        AQUtility.debug("before", bm.getWidth() + ":" + bm.getHeight());
        AQUtility.debug("after", result.getWidth() + ":" + result.getHeight());

        if (bm != result) {
            bm.recycle();
        }
    }

    return result;
}

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;
                }//  w  w w .j  a va 2  s  .  co  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;//from w  w  w.java2s . c o  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:com.liwn.zzl.markbit.DrawOptionsMenuActivity.java

private Uri rotateNormal(Uri uri) throws IOException {
    ExifInterface exif = new ExifInterface(uri.getPath());
    int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    int rotationInDegrees = exifToDegrees(rotation);
    Matrix matrix = new Matrix();
    if (rotation != 0) {
        matrix.preRotate(rotationInDegrees);
    }/*from  ww  w  . ja  v a2 s . c o m*/
    Bitmap srcBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
    Bitmap adjustedBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, MarkBitApplication.BIT_LCD_WIDTH,
            MarkBitApplication.BIT_LCD_HEIGHT, matrix, true);
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    adjustedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(this.getContentResolver(), adjustedBitmap, "Title", null);
    return Uri.parse(path);
}

From source file:Main.java

/**
 * get image orientation rotate degree//from  w  w  w.  j a v  a  2s . co  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

/**
 * ?/*  w  w  w .j  a 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;
}