**
Matisse使用心得
**
·Matisse是一个很成熟的框架,相信很多人在使用,废话不多说进入
·Matisse正常使用可以直接去github 搜索,我在这里只备注我自己觉得重要的地方
Glidev4+情况下
imageEngine(new MyGlideEngine())方法中需要自定义MyGlideEngine
public class MyGlideEngine implements ImageEngine {
@Override
public void loadThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri) {
RequestOptions options = new RequestOptions()
.centerCrop()
.placeholder(placeholder)//这里可自己添加占位
//.error(R.drawable.error)//这里可自己添加出错图
.override(resize, resize);
Glide.with(context)
.asBitmap() // some .jpeg files are actually gif
.load(uri)
.apply(options)
.into(imageView);
}
@Override
public void loadGifThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri) {
RequestOptions options = new RequestOptions()
.centerCrop()
.placeholder(placeholder)//这里可自己添加占位图 // .error(R.drawable.error)//这里可自己添加出错图
.override(resize, resize);
Glide.with(context)
.asBitmap() // some .jpeg files are actually gif
.load(uri)
.apply(options)
.into(imageView);
}
@Override
public void loadImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) {
RequestOptions options = new RequestOptions()
.centerCrop()
.override(resizeX, resizeY)
.priority(Priority.HIGH);
Glide.with(context)
.asBitmap() // some .jpeg files are actually gif
.load(uri)
.apply(options)
.into(imageView);
}
@Override
public void loadGifImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) {
RequestOptions options = new RequestOptions()
.centerCrop()
.override(resizeX, resizeY)
.priority(Priority.HIGH);
Glide.with(context)
.asBitmap() // some .jpeg files are actually gif
.load(uri)
.apply(options)
.into(imageView);
}
@Override
public boolean supportAnimatedGif() {
return true;
}
}
.captureStrategy(new CaptureStrategy(true, “包名.文件名称”))
//参数1 true表示拍照存储在共有目录,false表示存储在私有目录;参数2与 AndroidManifest中authorities值相同,用于适配6.0系统 必须设置
第二个参数必须和AndroidManifest中authorities一致
在res中创建xml文件
Matisse拍照拿不到真实路径问题:
/**
* 根据Uri获取文件真实地址 拍照/ matisse拍照
*/
public static String getRealFilePath1(Context context, Uri uri) {
if (null == uri) return null;
final String scheme = uri.getScheme();
String realPath = null;
if (scheme == null)
realPath = uri.getPath();
else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
realPath = uri.getPath();
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
Cursor cursor = context.getContentResolver().query(uri,
new String[]{MediaStore.Images.ImageColumns.DATA},
null, null, null);
if (null != cursor) {
if (cursor.moveToFirst()) {
int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
if (index > -1) {
realPath = cursor.getString(index);
}
}
cursor.close();
}
}
if (TextUtils.isEmpty(realPath)) {
if (uri != null) {
String uriString = uri.toString();
int index = uriString.lastIndexOf("/");
String imageName = uriString.substring(index);
File storageDir;
storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File file = new File(storageDir, imageName);
if (file.exists()) {
realPath = file.getAbsolutePath();
} else {
storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File file1 = new File(storageDir, imageName);
realPath = file1.getAbsolutePath();
}
}
}
return realPath;
}