Code example for ExifInterface

Methods: getAttributegetAttributeIntgetThumbnail

1
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                mBitmap.compress(CompressFormat.JPEG, 100, bos);
 
                mBitmap = getPreResizedImage(bos.toByteArray(), 200, 200);
 
                int orientation = mExifInterface.getAttributeInt(
                        ExifInterface.TAG_ORIENTATION,
                        ExifInterface.ORIENTATION_NORMAL);
                switch (orientation) {
                case ExifInterface.ORIENTATION_NORMAL: {
                    imageView.setImageBitmap(mBitmap);
 
                    break; 
                } 
                case ExifInterface.ORIENTATION_ROTATE_90: {
                    Matrix mat = new Matrix();
                    mat.postRotate(90);
 
                    // 回転したビットマップを作成 
                    Bitmap bmp = Bitmap.createBitmap(mBitmap, 0, 0,
                            mBitmap.getWidth(), mBitmap.getHeight(), mat, true);
 
                    imageView.setImageBitmap(bmp);
 
                    break; 
                } 
                case ExifInterface.ORIENTATION_ROTATE_180: {
                    Matrix mat = new Matrix();
                    mat.postRotate(180);
 
                    // 回転したビットマップを作成 
                    Bitmap bmp = Bitmap.createBitmap(mBitmap, 0, 0,
                            mBitmap.getWidth(), mBitmap.getHeight(), mat, true);
 
                    imageView.setImageBitmap(bmp);
 
                    break; 
                } 
                case ExifInterface.ORIENTATION_ROTATE_270: {
                    Matrix mat = new Matrix();
                    mat.postRotate(270);
 
                    // 回転したビットマップを作成 
                    Bitmap bmp = Bitmap.createBitmap(mBitmap, 0, 0,
                            mBitmap.getWidth(), mBitmap.getHeight(), mat, true);
 
                    imageView.setImageBitmap(bmp);
 
                    break; 
                } 
                } 
            } else { 
                try { 
                    Bitmap mBitmap = MediaStore.Images.Media.getBitmap(
                            getContentResolver(), bean.getBmpUri());
 
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    mBitmap.compress(CompressFormat.JPEG, 100, bos);
 
                    mBitmap = getPreResizedImage(bos.toByteArray(), 200, 200);
 
                    imageView.setImageBitmap(mBitmap);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } 
            } 
 
            return imageView;
        } 
 
        private Bitmap showThumbnail(ExifInterface exifInterface) {
            byte[] data = exifInterface.getThumbnail();
 
            if (null == data) {
                return null; 
            } 
 
            return BitmapFactory.decodeByteArray(data, 0, data.length);
        } 
 
        private void showExif(ExifInterface ei) {
            // API 5 
            String exifString = getExifString(ei, ExifInterface.TAG_DATETIME)
                    + "\n"; 
            exifString += getExifString(ei, ExifInterface.TAG_FLASH) + "\n";
            exifString += getExifString(ei, ExifInterface.TAG_GPS_LATITUDE)
                    + "\n"; 
            exifString += getExifString(ei, ExifInterface.TAG_GPS_LONGITUDE)
                    + "\n"; 
            exifString += getExifString(ei, ExifInterface.TAG_IMAGE_LENGTH)
                    + "\n"; 
            exifString += getExifString(ei, ExifInterface.TAG_IMAGE_WIDTH)
                    + "\n"; 
            exifString += getExifString(ei, ExifInterface.TAG_MAKE) + "\n";
            exifString += getExifString(ei, ExifInterface.TAG_MODEL) + "\n";
            exifString += getExifString(ei, ExifInterface.TAG_ORIENTATION)
                    + "\n"; 
            exifString += getExifString(ei, ExifInterface.TAG_WHITE_BALANCE)
                    + "\n"; 
 
            // API 8 
            exifString += getExifString(ei, ExifInterface.TAG_FOCAL_LENGTH)
                    + "\n"; 
            exifString += getExifString(ei, ExifInterface.TAG_GPS_DATESTAMP)
                    + "\n"; 
            exifString += getExifString(ei,
                    ExifInterface.TAG_GPS_PROCESSING_METHOD) + "\n";
            exifString += getExifString(ei, ExifInterface.TAG_GPS_TIMESTAMP)
                    + "\n"; 
 
            // API 9 
            exifString += getExifString(ei, ExifInterface.TAG_GPS_ALTITUDE)
                    + "\n"; 
 
            // Honeycomb 
            // exifString +=getExifString(ei, ExifInterface.TAG_APERTURE) + 
            // "\n"; 
            // exifString +=getExifString(ei, ExifInterface.TAG_EXPOSURE_TIME) + 
            // "\n"; 
            // exifString +=getExifString(ei, ExifInterface.TAG_ISO) + "\n"; 
 
            Log.d("Pic", exifString);
            Log.d("Pic", "  ");
        } 
 
        private String getExifString(ExifInterface ei, String tag) {
            return tag + ": " + ei.getAttribute(tag);
        } 
 
        public final int getCount() { 
            return exifInterfaceList.size();
        } 
Contextual code suggestions in your IDE  Get Codota for Java