美文网首页
知乎图片选择器Matisse使用

知乎图片选择器Matisse使用

作者: 灰色轨迹_e2d8 | 来源:发表于2019-04-08 16:49 被阅读0次

GitHub链接 https://github.com/zhihu/Matisse

使用心得

  • 需申请存储权限
  • 官方demo中没有申请相机权限,实际使用中发现不申请相机权限的话会崩溃
  • 使用带有相机的图片选择器
    java代码:
Matisse.from(ExecuteTaskFragment.this)
                .choose(MimeType.ofImage(), false) // 选择 mime 的类型
                .countable(true)
                .maxSelectable(num) // 图片选择的最多数量
                .capture(true)
                .captureStrategy(new CaptureStrategy(true, "ecp.PhotoPicker", "test"))
//                        .gridExpectedSize(getResources().getDimensionPixelSize(R.dimen.grid_expected_size))
                .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
                .thumbnailScale(0.85f) // 缩略图的比例
                .imageEngine(new GlideEngine()) // 使用的图片加载引擎
                .forResult(REQUEST_CODE_CHOOSE); // 设置作为标记的请求码

AndroidManifest.xml

        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="ecp.PhotoPicker"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/photo_path" />
        </provider>

photo_path.xml

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path
        name="my_images"
        path="Pictures"/>
</paths>

调用相机拍照后,照片将保存在外部存储地址的 pictures/test文件夹中。

相关文章

网友评论

      本文标题:知乎图片选择器Matisse使用

      本文链接:https://www.haomeiwen.com/subject/lqqpiqtx.html