影片直播原始碼,圖片選擇器ImagePicker

zhibo系統開發發表於2023-11-20

影片直播原始碼,圖片選擇器ImagePicker

引入

gradle
allprojects {
    repositories {
        maven { url '}
    }
}
implementation 'com.github.DL-ZhangTeng:ImagePicker:1.5.0'
//使用的三方
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'com.yalantis:ucrop:2.2.0'
implementation 'com.github.DL-ZhangTeng:RequestPermission:1.3.0'
implementation 'com.github.DL-ZhangTeng:Utils:2.2.0'


使用

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder()
                .provider(getPackageName() + ".FileProvider")
                .imageLoader(new GlideImageLoader()) //圖片載入器
                .iHandlerCallBack(new HandlerCallBack())    //圖片選擇器生命週期監聽(直接開啟攝像頭時無效)
                .multiSelect(true)                 //是否多選
                .isShowCamera(true)
                .isVideoPicker(true)              //是否選擇影片 預設false
                .isImagePicker(true)
                .imagePickerType(ImagePickerEnum.PHOTO_PICKER) //選擇器開啟型別
                .isMirror(false)                              //是否旋轉鏡頭
                .maxImageSelectable(9)                        //圖片可選擇數
                .maxHeight(1920)                              //圖片最大高度
                .maxWidth(1920)                               //圖片最大寬度
                .maxImageSize(15)                             //圖片最大大小Mb
                .maxVideoLength(5 * 1000)
                .maxVideoSize(180)
                .isCrop(true)
                .pathList(new ArrayList<>())
                .pickerThemeColorRes(R.color.image_picker_white)
                .pickerTitleColorRes(R.color.image_picker_text_black)
                .cropThemeColorRes(R.color.image_picker_white)
                .cropTitleColorRes(R.color.image_picker_text_black)
                .pickerBackRes(R.mipmap.image_picker_back_black)
                .pickerFolderRes(R.mipmap.image_picker_folder_black)
                .build();
        findViewById(R.id.iv).setOnClickListener(v -> {
//            imagePickerConfig.getPathList().clear();
            ImagePickerOpen.getInstance()
                    .setImagePickerConfig(imagePickerConfig)
                    .pathList(new ArrayList<>())
                    .open(this, 100);
        });
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 100 && data != null) {
            List<String> paths = ImagePickerOpen.getResultData(this, resultCode, data);
            ImagePickerOpen.getInstance().getImagePickerConfig().getImageLoader().loadImage(this, findViewById(R.id.iv), paths.get(0));
        }
    }
}
 
public class HandlerCallBack implements IHandlerCallBack<ImageInfo> {
    private String TAG = "---ImagePicker---";
    List<ImageInfo> photoList = new ArrayList<>();
    @Override
    public void onStart() {
        Log.i(TAG, "onStart: 開啟");
    }
    @Override
    public void onSuccess(List<ImageInfo> photoList) {
        this.photoList = photoList;
        Log.i(TAG, "onSuccess: 返回資料");
    }
    @Override
    public void onCancel() {
        Log.i(TAG, "onCancel: 取消");
    }
    @Override
    public void onFinish(List<ImageInfo> selectImage) {
    }
    @Override
    public void onError() {
        Log.i(TAG, "onError: 出錯");
    }
}


 以上就是影片直播原始碼,圖片選擇器ImagePicker, 更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2996168/,如需轉載,請註明出處,否則將追究法律責任。

相關文章