Example usage for android.media ExifInterface ExifInterface

List of usage examples for android.media ExifInterface ExifInterface

Introduction

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

Prototype

public ExifInterface(InputStream inputStream) throws IOException 

Source Link

Document

Reads Exif tags from the specified image input stream.

Usage

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  ww .  ja  v  a 2s. com
    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.example.lowviscam.GalleryActivity.java

/**
 * Generate the list of all coupons.//from  w w  w  .  j a  va2  s.c o m
 * @return The list of coupons.
 * @throws IOException 
 */
private List<Coupon> createAllCoupons() throws IOException {
    // TODO: Customize this list of coupons for your personal use.
    List<Coupon> coupons = new ArrayList<Coupon>();
    File list[] = mediaStorageDir.listFiles();
    for (int i = list.length - 1; i > -1; i--) {

        //Get text tag
        String tag = "NA";
        try {
            ExifInterface exif = new ExifInterface(list[i].getPath());
            tag = exif.getAttribute("UserComment");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        coupons.add(new Coupon(tag, list[i].getName()));
    }

    // You can add a title, subtitle, and a photo (in the assets directory).

    return coupons;
}

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;
    }// w w w .  j  a va 2 s  . c  om
    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 w  w  .  ja va 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;
                }//from   w  w w.ja  v  a 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.example.lowviscam.GalleryActivity.java

private List<Coupon> createSearchedCoupons(String query) throws IOException {
    // TODO: Customize this list of coupons for your personal use.
    List<Coupon> coupons = new ArrayList<Coupon>();

    numSearchResults = 0;/*from   www  .j a va2  s.c  o m*/

    File list[] = mediaStorageDir.listFiles();

    int j = 0;
    for (int i = list.length - 1; i > -1; i--) {

        //Get text tag
        String tag = "NA";
        try {
            ExifInterface exif = new ExifInterface(list[i].getPath());
            tag = exif.getAttribute("UserComment");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        if (tag.toLowerCase().contains(query.toLowerCase())) {
            coupons.add(new Coupon(tag, list[i].getName()));
            tagList[j] = tag;
            numSearchResults++;
            j++;
        }
    }

    // You can add a title, subtitle, and a photo (in the assets directory).

    return coupons;
}

From source file:com.nextgis.mobile.forms.CameraFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    sensorManager.unregisterListener(sensorListener);
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        //add angle
        float dfAngle = 0;
        try {/*  www . ja  v a2 s . com*/
            ExifInterface exif = new ExifInterface(imgFile.getPath());
            String sDate = exif.getAttribute(ExifInterface.TAG_DATETIME);
            Date datetime = stringToDate(sDate, "yyyy:MM:dd HH:mm:ss");
            Log.d(TAG, "image date: " + datetime.toString());
            long testMilli = datetime.getTime();

            long nDif = 1000000;
            for (long n : mAngles.keySet()) {
                long nDifTmp = Math.abs(testMilli - n);
                if (nDifTmp < nDif) {
                    nDif = nDifTmp;
                    dfAngle = (Float) mAngles.get(n);
                }
            }
            Log.d(TAG, "image angle: " + dfAngle);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String listItem;
        if (data != null) {
            Uri outPath = data.getData();
            listItem = outPath.getLastPathSegment();
        } else {
            listItem = fileName;
        }
        HashMap<String, Object> hm = new HashMap<String, Object>();
        hm.put(IMG_NAME, listItem);
        String sAngle = CompassFragment.formatNumber(dfAngle, 0, 0) + CompassFragment.DEGREE_CHAR + " "
                + CompassFragment.getDirectionCode(dfAngle, getResources());
        hm.put(IMG_ROT, sAngle);

        listItems.add(hm);

        adapter.notifyDataSetChanged();

        InputPointActivity activity = (InputPointActivity) getActivity();
        if (activity == null)
            return;
        activity.AddImage(listItem, dfAngle);
    }
}

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;/* w  w w  . j  a  va 2 s.  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);
    }/* w  w  w  .j  a 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  ww  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;
}