Giter Site home page Giter Site logo

imagepicker's Introduction

ImagePicker

Library for picking pictures from gallery,camera or custom gallery, support multiple!

可以轻松从系统图库、拍照、自定义图库中选择图片,自定义图库支持多选。

截图

Demo截图

如何使用

初始化&调用

   ImagePicker mImagePicker = new ImagePicker(this);
   
   // 调用方法:
   // 打开相机 or
   mImagePicker.openCamera(CallbackForCamera callback);
   // 打开系统图库 or
   mImagePicker.openGallery(CallbackForGallery callback);
   // 打开自定义图库 or
   mImagePicker.openImagePicker(boolean isMultiple, CallbackForImagePicker callback);

在OnActivityResult委托给ImagePicker处理

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // 委托处理
        mImagePicker.delegateActivityResult(requestCode, resultCode, data);
    }

对于CallbackForXXX,都有:

    @Override
    public void onError(Exception error) {
        // 选取图片异常
    }

    /**
    *   对CallbackForImagePicker,不管单选多选 入参为:List<String>
    */
    @Override
    public void onComplete(String imagePath) {
        // 选取图片完成,参数为 图片文件路径
    }

    /**
    *   仅CallbackForCamera时 有该方法,可以在此删除拍摄的临时照片
    */
    @Override
    public void onCancel(String imagePath) {
        // 选取图片取消,参数为 图片文件路径
    }

AndroidManifest.xml文件里, 对于targetSdkVersion > 22的,请在openXX前,自行检查适配Android M的权限

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<activity android:name="me.yokeyword.imagepicker.ImagePickerActivity"/>

使用自定义图库时,如果你想更改TitleBar的样式,可以参考下面的代码或Sample项目

  // 请在openImagePicker()方法之前调用
        mImagePicker.titleBar()
                // 设置标题文字颜色
                .setTitleColor(Color.RED)
                // 设置标题文字大小
                .setTitleSize(14)
                // 设置标题位置:居左LEFT 或 居中CENTER
                .setTitleLocation(TitleBar.CENTER)
                // 设置Bar颜色
                .setBarBackground(Color.WHITE)
                // 设置Bar高度
                .setBarHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 52, getResources().getDisplayMetrics()))
                .build();

Gradle dependency

dependencies {
    compile 'me.yokeyword:imagepicker:0.2.1'
}

License

Copyright 2015 YoKeyword

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

imagepicker's People

Contributors

yokeyword avatar

Watchers

James Cloos avatar akingyin 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.