Android 图片查看器选择器 PictureSelector

 

 

1、依赖:

implementation 'com.github.LuckSiege.PictureSelector:picture_library:v2.2.4'

 

2、配置:

allprojects {
    repositories {
        google()

        jcenter()

        maven { url 'https://jitpack.io' }
    }
}

 

 

3、应用:

List list=new ArrayList<>();
for (int i=0;i<5;i++){
    LocalMedia media=new LocalMedia();
    String url="https://zhongshop.oss-cn-beijing.aliyuncs.com/21a1d4901770c52f5af32dc69e4601f4.png";
    media.setPath(url);
    list.add(media);
}


PictureSelector.create(this).themeStyle(R.style.picture_default_style)
        .openExternalPreview(0, list);





选择器:

    private void initSelector(){
        PictureSelector.create(this)
                .openGallery(PictureConfig.TYPE_IMAGE)
                .imageSpanCount(4)// 每行显示个数 int
                .maxSelectNum(1)
                .selectionMode(PictureConfig.SINGLE)// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
                .previewImage(true)// 是否可预览图片 true or false
                .isCamera(true)// 是否显示拍照按钮 true or false
                .imageFormat(PictureMimeType.JPEG)// 拍照保存图片格式后缀,默认jpeg
                .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
                .setOutputCameraPath(Const.IMG_PATH)// 自定义拍照保存路径,可不填
                .enableCrop(true)// 是否裁剪 true or false
                .compress(true)// 是否压缩 true or false
//                .compressSavePath(Const.IMG_PATH)//压缩图片保存地址
                .freeStyleCropEnabled(true)// 裁剪框是否可拖拽 true or false
                .showCropGrid(true)// 是否显示裁剪矩形网格 圆形裁剪时建议设为false    true or false
                .forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == -1 && data != null) {
            switch (requestCode) {
                case 100:
                    break;
                case PictureConfig.CHOOSE_REQUEST:
                    List selectList = PictureSelector.obtainMultipleResult(data);

                    myAdapter.notifyDataSetChanged();
//                    Glide.with(MerchantLicenseActivity.this).load(selectList.get(0).getCompressPath()).into(iv_license);
                    uploadImg(selectList.get(0).getCompressPath());
                    break;
            }
        }
    }

你可能感兴趣的:(Android 图片查看器选择器 PictureSelector)