在android多媒体开发中,ExifInterface(exif exchangeable image file) ,这个接口提供了图片文件的旋转,gps,时间等信息。

 Bitmap bitmap =null;        int scallType = 0;        try {             ExifInterface exifInterface = new ExifInterface(file.getPath());             int result = exifInterface.getAttributeInt(                     ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);             int rotate = 0;             switch(result) {             case ExifInterface.ORIENTATION_ROTATE_90:                 rotate = 90;                 break;             case ExifInterface.ORIENTATION_ROTATE_180:                 rotate = 180;                 break;             case ExifInterface.ORIENTATION_ROTATE_270:                 rotate = 270;                 break;             default:                 break;             }             BitmapFactory.Options options = new BitmapFactory.Options();            options.inPreferredConfig = Bitmap.Config.RGB_565;            // 初めのデコードはサイズ取得のみ            options.inJustDecodeBounds = true;            BitmapFactory.decodeFile(filePath, options);            if (options.outWidth < 0 || options.outHeight < 0) {                return null;            }                         scallType = genScallType(context, options);                        options.inJustDecodeBounds = false;            bitmap=  BitmapFactory.decodeFile(filePath, options);            if(rotate > 0) {                 Matrix matrix = new Matrix();                 matrix.setRotate(rotate);                 Bitmap rotateBitmap = Bitmap.createBitmap(                         bitmap, 0, 0, options.outWidth, options.outHeight, matrix, true);                 if(rotateBitmap != null) {                     bitmap.recycle();                     bitmap = rotateBitmap;                 }             }         } catch (IOException e) {             e.printStackTrace();         } 


public int getAttributeInt (String tag, int defaultValue)

Since: API Level 5

Returns the integer value of the specified tag. If there is no such tag in the JPEG file or the value cannot be parsed as integer, return defaultValue.

(在指定的tag后,返回一个int类型的值,这里传入的是ExifInterface.TAG_ORIENTATION,所以会返回一个角度的int类型的值,当我们用android 平板电脑,或者手机横屏拍照片时并希望把它作为背景设置在所在的应用背景,而且不希望背景会产生旋转90度得现象)

更多相关文章

  1. Android(安卓)JNI入门第三篇——jni头文件分析
  2. android广播的两种方式!
  3. Drawable、Bitmap、byte[]之间的转换
  4. Android笔记之Ripple
  5. 【android积累】
  6. Android系统默认Home应用程序(Launcher)的启动过程源代码分析(4)
  7. 图片背景平铺
  8. RadioButton改变背景颜色
  9. Android设置背景颜色渐变

随机推荐

  1. android分辨率适配
  2. android:gravity/android:layout_gravity
  3. Android开发经典书籍下载——《Android 4
  4. ch019 Android surfaceView
  5. [Android] Android 锁屏实现与总结 (一)
  6. Android 开发有哪些新技术出现?
  7. ch018 Android webview
  8. Android Theme主题继承(SDK下主题和v7包下
  9. Android控制文字水平间距android:letterS
  10. Android Contacts(一)—— 读取联系人