Giter VIP home page Giter VIP logo

imageselector's Introduction

本项目已停止维护

本项目的背景是当时没有十分好用的图片选择的库,所以自己写了一个。

目前已经找到一个功能很齐全的库 PictureSelector 推荐大家使用

ImageSelector 简介

####近期将会重构代码,修复bug,感谢各位使用者的支持重构地址 Android自定义相册,实现了拍照、图片选择(单选/多选)、ImageLoader无绑定 任由开发者选择

###GitHub 项目地址

多选 截图

Download Apk

ImageSelector 优点

  • UI重改
  • 所有功能可配置
  • 解决OOM情况
  • 图片多选、单选
  • 支持裁剪功能

Gif展示

单选截图 多选

版本说明

1.3.0

  • 合并 由 xxxifan 提供的优化方案,配置只需要配置一次,需要用的地方可以直接 open。
  • 修改如果手机中没有图片,选择图片夹闪退的问题
  • 隐藏调用该图片选择器时,所拍摄的照片和裁剪的图片,改善选择图片时存在的垃圾图片。
  • 修改最低版本兼容,由原来的 API 15 降到 API 14,兼容 Android 4.0 以上系统。

使用说明

步骤一:

通过Gradle抓取

dependencies {
    compile 'com.yancy.imageselector:imageselector:1.3.3'
}

步骤二:

AndroidManifest.xml 中 添加 如下权限

<!-- 从sdcard中读取数据的权限 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- 往sdcard中写入数据的权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

步骤三:

#####创建 图片加载器 (其中可以按照 喜好 使用不同的 第三方图片加载框架 以下为Glide示例)

public class GlideLoader implements com.yancy.imageselector.ImageLoader {

   @Override
   public void displayImage(Context context, String path, ImageView imageView) {
       Glide.with(context)
               .load(path)
               .placeholder(com.yancy.imageselector.R.mipmap.imageselector_photo)
               .centerCrop()
               .into(imageView);
   }

}

步骤四:

配置 ImageConfig

UI 视图配置
 ImageConfig imageConfig
      = new ImageConfig.Builder(new GlideLoader())
     // 如果在 4.4 以上,则修改状态栏颜色 (默认黑色)
     .steepToolBarColor(getResources().getColor(R.color.blue))
     // 标题的背景颜色 (默认黑色)
     .titleBgColor(getResources().getColor(R.color.blue))
     // 提交按钮字体的颜色  (默认白色)
     .titleSubmitTextColor(getResources().getColor(R.color.white))
     // 标题颜色 (默认白色)
     .titleTextColor(getResources().getColor(R.color.white))
     .build();
多选
 ImageConfig imageConfig
        = new ImageConfig.Builder(new GlideLoader())
        .steepToolBarColor(getResources().getColor(R.color.blue))
        .titleBgColor(getResources().getColor(R.color.blue))
        .titleSubmitTextColor(getResources().getColor(R.color.white))
        .titleTextColor(getResources().getColor(R.color.white))
        // 开启多选   (默认为多选) 
        .mutiSelect()
        // 多选时的最大数量   (默认 9 张)
        .mutiSelectMaxSize(9)
        // 开启拍照功能 (默认关闭)
        .showCamera()
        // 已选择的图片路径
        .pathList(path)
        // 拍照后存放的图片路径(默认 /temp/picture) (会自动创建)
        .filePath("/ImageSelector/Pictures")
        .build();


ImageSelector.open(MainActivity.this, imageConfig);   // 开启图片选择器
单选
 ImageConfig imageConfig
        = new ImageConfig.Builder(new GlideLoader())
        .steepToolBarColor(getResources().getColor(R.color.blue))
        .titleBgColor(getResources().getColor(R.color.blue))
        .titleSubmitTextColor(getResources().getColor(R.color.white))
        .titleTextColor(getResources().getColor(R.color.white))
        // 开启单选   (默认为多选) 
        .singleSelect()
        // 开启拍照功能 (默认关闭)
        .showCamera()
        // 拍照后存放的图片路径(默认 /temp/picture) (会自动创建)
        .filePath("/ImageSelector/Pictures")
        .build();


ImageSelector.open(MainActivity.this, imageConfig);   // 开启图片选择器
单选1:1 便捷截图
 ImageConfig imageConfig
        = new ImageConfig.Builder(new GlideLoader())
        .steepToolBarColor(getResources().getColor(R.color.blue))
        .titleBgColor(getResources().getColor(R.color.blue))
        .titleSubmitTextColor(getResources().getColor(R.color.white))
        .titleTextColor(getResources().getColor(R.color.white))
        // (截图默认配置:关闭    比例 1:1    输出分辨率  500*500)
        .crop()  
        // 开启单选   (默认为多选) 
        .singleSelect()
        // 开启拍照功能 (默认关闭)
        .showCamera()
        // 拍照后存放的图片路径(默认 /temp/picture) (会自动创建)
        .filePath("/ImageSelector/Pictures")
        .build();


ImageSelector.open(MainActivity.this, imageConfig);   // 开启图片选择器
单选自定义截图
 ImageConfig imageConfig
        = new ImageConfig.Builder(new GlideLoader())
        .steepToolBarColor(getResources().getColor(R.color.blue))
        .titleBgColor(getResources().getColor(R.color.blue))
        .titleSubmitTextColor(getResources().getColor(R.color.white))
        .titleTextColor(getResources().getColor(R.color.white))
        // (截图默认配置:关闭    比例 1:1    输出分辨率  500*500)
        .crop(1, 2, 500, 1000) 
        // 开启单选   (默认为多选) 
        .singleSelect()
        // 开启拍照功能 (默认关闭)
        .showCamera()
        // 拍照后存放的图片路径(默认 /temp/picture) (会自动创建)
        .filePath("/ImageSelector/Pictures")
        .build();


ImageSelector.open(MainActivity.this, imageConfig);   // 开启图片选择器

步骤五:

onActivityResult 中获取选中的照片路径 数组 :

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 super.onActivityResult(requestCode, resultCode, data);
  if (requestCode == ImageSelector.IMAGE_REQUEST_CODE && resultCode == RESULT_OK && data != null) {
  
    // Get Image Path List
     List<String> pathList = data.getStringArrayListExtra(ImageSelectorActivity.EXTRA_RESULT);

     for (String path : pathList) {
         Log.i("ImagePathList", path);
     }
  }
}

代码示例

历史版本说明

1.3.0

  • 合并 由 xxxifan 提供的优化方案,现在在fragment 中也可以进行调用
  • 修改如果手机中没有图片,选择图片夹闪退的问题
  • 隐藏调用该图片选择器时,所拍摄的照片和裁剪的图片,改善选择图片时存在的垃圾图片。
  • 修改最低版本兼容,由原来的 API 15 降到 API 14,兼容 Android 4.0 以上系统。

1.2.0

  • 新增截图功能

1.1.1

  • 修改APP名被覆盖的bug

1.1.0

  • 优化代码,开放部分UI接口

1.0.0

  • 选择图片功能

关于作者

imageselector's People

Contributors

xxxifan avatar yancyye avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imageselector's Issues

Exception while processing task java.io.IOException: Please correct the above warnings first.

com.yancy.imageselector.ImageSelector: can't find referenced field 'int open_camera_fail' in program class com.yancy.imageselector.R$string  
com.yancy.imageselector.ImageSelector: can't find referenced field 'int empty_sdcard' in program class com.yancy.imageselector.R$string  
there were 2 unresolved references to program class members.  
Exception while processing task java.io.IOException: Please correct the above warnings first.  

com.yancy.imageselector.ImageConfig.getSteepToolBarColor()' on a null object reference

java.lang.RuntimeException:Unable to start activity ComponentInfo{cn.grass.meter/com.yancy.imageselector.ImageSelectorActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.yancy.imageselector.ImageConfig.getSteepToolBarColor()' on a null object reference

2 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2796)
3 ......
4 Caused by:
5 java.lang.NullPointerException:Attempt to invoke virtual method 'int com.yancy.imageselector.ImageConfig.getSteepToolBarColor()' on a null object reference
6 com.yancy.imageselector.ImageSelectorActivity.onCreate(ImageSelectorActivity.java:43)
7 android.app.Activity.performCreate(Activity.java:6910)
8 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
9 cn.jiguang.a.a.c.a.a.d.callActivityOnCreate(Unknown Source)
10 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2749)
11 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2867)
12 android.app.ActivityThread.-wrap12(ActivityThread.java)
13 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1570)
14 android.os.Handler.dispatchMessage(Handler.java:105)
15 android.os.Looper.loop(Looper.java:156)
16 android.app.ActivityThread.main(ActivityThread.java:6595)
17 java.lang.reflect.Method.invoke(Native Method)
18 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
19 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)

使用相机并截图时,返回的是完整的图片而不是截出来的图片

看了图片目录,两个图片都存在,但是返回的图片如题所说是完整的。
感觉问题出现在/imageselector/src/main/java/com/yancy/imageselector/ImageSelectorActivity.java的onCameraShot函数

    public void onCameraShot(File imageFile) {
        if (imageFile != null) {
            Intent data = new Intent();
            pathList.add(imageFile.getAbsolutePath());
            data.putStringArrayListExtra(EXTRA_RESULT, pathList);
            setResult(RESULT_OK, data);
            exit();
        }
        if (imageFile != null) {
            if (imageConfig.isCrop()) {
                crop(imageFile.getAbsolutePath(), imageConfig.getAspectX(), imageConfig.getAspectY(), imageConfig.getOutputX(), imageConfig.getOutputY());
            } else {
                Intent data = new Intent();
                pathList.add(imageFile.getAbsolutePath());
                data.putStringArrayListExtra(EXTRA_RESULT, pathList);
                setResult(RESULT_OK, data);
                exit();
            }
        }

两个if的判断条件一样,那样应该后一个if是无效的。
但是同时我使用相机的时候的确是进入了截图的界面,感觉是进入了第二个if并执行截图操作了的。
我正在想办法调试。在这之前也发给你看看吧。

该项目配合gilde使用时,快速滑动后选择图片,图片展示recyclerview展示图片为空白的问题

特别是容易出现在进入图片选择器----快速翻页(此时图片出显示完整)----选择图片----确定----返回展示列表----发现显示空白
肉眼观察没有出现gilde预加载的图片(.placeholder),没有出现gilde加载失败的图片(.error)
打印log发现gilde加载图片的path都是正常的(包括缓存的和图片本身在sd卡的路径),path指向的图片也是正常的

虽然这样的极限操作,有点不好搞。
但是我发现微信就不会出现这样的情况

一点问题

第一次进入选择界面会出现大部分图片加载不出来,只显示默认图片,之后点进去偶尔会出现加载不出图片的情况,全部加载出来后滑动显示倒是很流畅,希望作者能改进一下

在部分安卓6.01的机器上闪退问题

目前测试中,在小米5的miui8,安卓版本6.01系统下,在进入选择图片模式,如果直接点击图片而不是右上角的checkbox,选择图片页面会闪退,导致app进入假死状态,同样的问题也在三星s7安卓6.01系统上,希望作者能给予答复!不尽感激!

Error : endless add All Images

请点击照片的文件夹,整个文件夹和重叠的照片总数

endless add All Images and endless add same folder...

I guess the cause of this problem is

new Handler().postDelayed(new Runnable() {
@OverRide
public void run() {
folderPopupWindow.dismiss();
if (index == 0) {
getActivity().getSupportLoaderManager().initLoader(LOADER_ALL, null, mLoaderCallback);

How to fix it ?? please help me :)

图片多选问题

选中的图片切换到其他文件夹点击第一下状态变了,但是界面显示没反应。之后图片选中的状态和界面显示的就会相反。

android N 拍照错误

android.os.FileUriExposedException: file:///storage/emulated/0/ImageSelector/Pictures/20171110133645.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1816)
at android.net.Uri.checkFileUriExposed(Uri.java:2350)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:837)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9058)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9043)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1530)
at android.app.Activity.startActivityForResult(Activity.java:4391)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
at android.support.v4.app.ActivityCompat.startActivityForResult(ActivityCompat.java:152)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:798)
at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:907)
at android.support.v4.app.Fragment.startActivityForResult(Fragment.java:1028)
at android.support.v4.app.Fragment.startActivityForResult(Fragment.java:1017)
at com.yancy.imageselector.b.b(ImageSelectorFragment.java:326)
at com.yancy.imageselector.b.h(ImageSelectorFragment.java:46)
at com.yancy.imageselector.b$4.onItemClick(ImageSelectorFragment.java:203)
at android.widget.AdapterView.performItemClick(AdapterView.java:313)
at android.widget.AbsListView.performItemClick(AbsListView.java:1201)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3195)
at android.widget.AbsListView$3.run(AbsListView.java:4138)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)

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.