Coder Social home page Coder Social logo

imagepicker's Introduction

ImagePicker

图片选择器

License Download API

演示

准备工作

1.获取依赖

project的build.gradle

allprojects {
    repositories {
        ......       
        maven { url "https://jitpack.io" } 
        maven { url  "https://dl.bintray.com/yongdongji/android" }
    }
}

app的build.gradle Download

 
implementation ('www.weimu.io:imagepicker:{latest}@aar'){ transitive = true }
//以下为此aar所依赖的第三方
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
implementation 'com.isseiaoki:simplecropview:1.1.7@aar'
implementation 'top.zibin:Luban:1.1.3'

2.增加权限

<!-- 相机权限 -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- 存储权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

3.增加FileProvider【适配7.0】

注意:此处的android:resource="@xml/filepaths"自己谷歌或直接获取demo文件

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/filepaths" />
</provider>

用法

1.1.打开图库

ImagePicker.getInstance().pickImage(activity);

多参数调用

/**
 * @param activity
 * @param maxSelectNum 最大选择图片数          default=9
 * @param mode 图库模式【单选】【多选】         default=ImageSelectorActivity.MODE_MULTIPLE
 * @param enableCamera 是否启用摄像头          default=true
 * @param enablePreview 是否打开预览           default=true
 * @param enableCrop 是否进行裁剪【单选可用】   default=false
 */
ImagePicker.getInstance().pickImage(activity, 9, ImageSelectorActivity.MODE_MULTIPLE, true, true, false);

1.2.直接拍张

ImagePicker.getInstance().takePhoto(activity);

多参数调用

/**
 * @param activity
 * @param enableCrop 是否启用裁剪 default=false
 */
ImagePicker.getInstance().takePhoto(activity,false);

2.接收结果信息

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(resultCode == RESULT_OK && requestCode == ImageSelectorActivity.REQUEST_IMAGE){
        ArrayList<String> images = (ArrayList<String>) data.getSerializableExtra(ImageSelectorActivity.REQUEST_OUTPUT);
        // do something
    }
}

imagepicker's People

Contributors

familqasimov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.