L版本设置壁纸为什么只支持JPEG格式图片旋转设置
来源:互联网 发布:阿里妈妈淘宝客注册 编辑:程序博客网 时间:2024/05/13 08:52
在L版本中,图片旋转之后,设置壁纸,只有JPEG格式可以保存为旋转后的图片方向。
这里设置使用的L版本自带的Launcher3中\packages\apps\Launcher3\WallpaperPicker\src\com\android\launcher3\WallpaperCropActivity.java
大概设置壁纸流程:1,首先 通过 Uri /path/Resurce 三种资源都可以获得图片,;
2,其次通过BitmapCropTask extends AsyncTask<Void, Void, Boolean>将资源解析;
3,调用WallpaperManager来讲图片资源实例到系统壁纸中。
阅读这段代码,可以发现设置壁纸有很多方法入口,比如
protected void cropImageAndSetWallpaper(Uri uri,
OnBitmapCroppedHandler onBitmapCroppedHandler, final boolean finishActivityWhenDone)
或者
protected void cropImageAndSetWallpaper(
Resources res, int resId, final boolean finishActivityWhenDone)
但是设计到图片的方向最后都会归于一个方法————— private static int getRotationFromExifHelper(String path, Resources res, int resId, Context context, Uri uri)
那么我们来看一下这个方法的具体代码:
private static int getRotationFromExifHelper( String path, Resources res, int resId, Context context, Uri uri) { ExifInterface ei = new ExifInterface();//生成ExifInterface对象 InputStream is = null; BufferedInputStream bis = null; try { if (path != null) { ei.readExif(path);//读取资源图片的Exif头信息 } else if (uri != null) { is = context.getContentResolver().openInputStream(uri); bis = new BufferedInputStream(is); ei.readExif(bis); //<span style="font-family: Arial, Helvetica, sans-serif;">读取资源图片的Exif头信息</span> } else { is = res.openRawResource(resId); bis = new BufferedInputStream(is); ei.readExif(bis); //<span style="font-family: Arial, Helvetica, sans-serif;">读取资源图片的Exif头信息</span> } Integer ori = ei.getTagIntValue(ExifInterface.TAG_ORIENTATION); //直接获取Exif头信息中的方向值 if (ori != null) { return ExifInterface.getRotationForOrientationValue(ori.shortValue()); } } catch (IOException e) { Log.w(LOGTAG, "Getting exif data failed", e); } catch (NullPointerException e) { // Sometimes the ExifInterface has an internal NPE if Exif data isn't valid Log.w(LOGTAG, "Getting exif data failed", e); } finally { Utils.closeSilently(bis); Utils.closeSilently(is); } return 0; //方向值一般都是 0,90,180,270 所以当没有获取到资源的方向,默认返回0,即没有旋转的图片 }这个方法有一个极其重要的类,就是ExifInterface;我们可以主要读取图片方向的代码都是ExifInterface的一些方法,那么这个ExifInterface到底是怎么来的呢。
我们来看一下framework里面对于ExifInterface的描述
/** * This is a class for reading and writing Exif tags in a JPEG file. */public class ExifInterface { // The Exif tag names /** Type is int. */ public static final String TAG_ORIENTATION = "Orientation"; /** Type is String. */ public static final String TAG_DATETIME = "DateTime"; /** Type is String. */ public static final String TAG_MAKE = "Make"; /** Type is String. */ public static final String TAG_MODEL = "Model";... ...This is a class for reading and writing Exif tags in a JPEG file.原来这个类仅仅是为了JPEG图片准备的。
百度百科的描述:
- L版本设置壁纸为什么只支持JPEG格式图片旋转设置
- ProgressBar设置旋转图片
- 设置图片为壁纸的源代码
- QTE中如何支持GIF、JPEG等格式图片
- QTE中如何支持GIF、JPEG等格式图片
- L版本修改默认静态壁纸wallpaper
- Launcher: 设置壁纸_IntentChooser
- 设置开机动态壁纸
- 设置默认壁纸
- 设置默认动态壁纸
- android-设置屏幕壁纸
- Android壁纸设置
- android 设置壁纸
- Android setWallpaper()设置壁纸
- Android设置壁纸
- Android Launcher 设置壁纸
- Android设置壁纸
- android 设置壁纸
- Mybaits简单实例
- hdu 3938 Portal
- [刷题]Search in Rotated Sorted Array
- hdu 4006 AvlTree
- 改习题2-1
- L版本设置壁纸为什么只支持JPEG格式图片旋转设置
- Partition List
- inline function(内联函数)
- 删除重复字符
- 电信141p51第14题
- windows7 64位操作系统上使vs2010和vs2013能够并存的处理方法
- mybatis 动态SQL语句
- redis入门
- 数据库连接池c3p0/dbcp