ImagePicker

½éÉÜ£º

Ò»¿î¹¦Äܳ¬Ç¿µÄͼƬѡÔñÆ÷¡£Ö§³Ö³¬´óͼԤÀÀ(±ÈÈç10000*5000µÄͼ)£¬Ö§³ÖͼƬ²Ã¼ô£¬¿ÉÅäÖÃÍ·ÏñģʽºÍÆÕͨģʽ£¬Ö§³Ö¶¯Ì¬ÅäÖÃImageLoaderÒÔÖ§³Ö¶àÖÖͼƬ¼ÓÔؿ⣬ÒÔ¼°ÊµÏÖÁ÷³©µÄÌøת¶¯»­

ÔËÐÐЧ¹û£º

ʹÓÃ˵Ã÷£º

¸ÃÏîÄ¿µÄ³¬´óͼƬԤÀÀ²ÎÕÕÁËÕâ¸öÏîÄ¿

ÈçºÎÌí¼Ó

Gradle

1.ÔÚProjectµÄbuild.gradle ÖÐÌí¼Ó²Ö¿âµØÖ·

 // JitPack²Ö¿âµØÖ·
 maven { url "https://jitpack.io" }

ʾÀý£º

allprojects {
    repositories {
        jcenter()
        // JitPack²Ö¿âµØÖ·
        maven { url "https://jitpack.io" }
    }
}

2.ÔÚappĿ¼ÏµÄbuild.gradleÖÐÌí¼ÓÒÀÀµ

    //SImagePicker
    compile 'com.github.martin90s:ImagePicker:v1.2'

ÈçºÎʹÓÃ

1.Ê×Ïȳõʼ»¯£¨ÍƼöÔÚApplicationµÄoncreateÖе÷Óã©

 SImagePicker.init(new PickerConfig.Builder().setAppContext(this)
             .setImageLoader(new FrescoImageLoader())
            .setToolbaseColor(getColor(R.color.colorPrimary))
            .build());

2.ÔÚÐèҪѡÔñͼƬµÄµØ·½µ÷ÓÃ

 SImagePicker
            .from(MainActivity.this)
            .maxCount(9)
            .rowCount(3)
            .pickMode(SImagePicker.MODE_IMAGE)
            .fileInterceptor(new SingleFileLimitInterceptor())
            .forResult(REQUEST_CODE_IMAGE);

¿ÉÅäÖÃÏî

1.È«¾ÖÅäÖ㨼´³õʼ»¯Ê±´«ÈëµÄPickerConfig,´ËÅäÖÃ×÷ÓÃÓÚSImagePickerÕû¸öʹÓùý³Ì£©

ÅäÖòÎÊý²ÎÊýº¬Òå
setImageLoader(ImageLoader)ʹÓõÄͼƬ¼ÓÔØÆ÷¡£demo¹¤³ÌÖÐʵÏÖÁËFrescoºÍGlideÁ½ÖÖImageLoader,¿ÉÒԲο¼
setToolbarColor(int)PickerµÄÖ÷É«µ÷£¬Ä¬ÈÏÖµÊÇAppµÄprimaryColor
setAppContext(Context)PickerÄÚ²¿Óõ½µÄContext£¬´«ÈëApplicationContext¼´¿É

2.µ¥´ÎÅäÖ㨼´Ã¿´Îµ÷ÓÃSImagePickerʱ´«ÈëµÄ²ÎÊý£¬´Ë²ÎÊýÖ»¶ÔÕâ´Îµ÷ÓÃÉúЧ£©

ÅäÖòÎÊý²ÎÊýº¬Òå
from(Activity or Fragment)µ÷ÓÃͼƬѡÔñÆ÷¿É´ÓActivity»òÕßFragment½øÈ룬×îºóµÄ½á¹û»áÔÚonActivityResult()·µ»Ø£¬ÏÖÔÚ·µ»ØµÄ½á¹ûÓÐÁ½¸öÖµ£¬Óû§Ñ¡ÔñµÄͼƬµÄ·¾¶Áбídata.getStringArrayListExtra(PhotoPickerActivity.EXTRA_RESULT_SELECTION);Óû§ÊÇ·ñÑ¡ÔñÁËԭͼdata.getBooleanExtra(PhotoPickerActivity.EXTRA_RESULT_ORIGINAL, false);
maxCount(int)´Ë´ÎÑ¡ÔñÔÊÐíµÄ×î´óÑ¡ÔñÊýÁ¿£¬Ä¬ÈÏÊÇ1.±ÈÈç·¢ÅóÓÑȦ×î¶àÑ¡Ôñ9ÕÅͼ¾Í´«9
rowCount(int)ͼƬÁÐ±íµ¥ÅÅչʾ¶àÉÙÕÅͼ
setSelected(List)ĬÈÏÒѾ­±»Ñ¡ÖеÄͼƬ
pickMode(int)ѡͼµÄģʽ£¬ÏÖÔÚÓÐÍ·ÏñģʽºÍÆÕͨģʽÁ½ÖÖ£¬Í·ÏñģʽѡÖÐͼƬºóĬÈÏ»áÌøµ½Í¼Æ¬²Ã¼ôÒ³ÃæÇÒĬÈÏÖ»ÄÜÑ¡ÔñÒ»ÕÅ
cropFilePath(String)Í·ÏñģʽϲüôͼƬ´æ·ÅµØÖ·
showCamera(boolen)ÊÇ·ñҪչʾÅÄÕÕÈë¿Ú
pickText(int)PickerÀïÓÒϽÇչʾµÄÎÄ×ÖÐÅÏ¢£¨±ÈÈçÅäÖÃÑ¡Ôñ£¬·¢ËÍ£¬Íê³É£©
fileInterceptor(FileChooseInterceptor)ͼƬ¹ýÂËÆ÷£¬±ÈÈçÓû§Ñ¡ÔñµÄµ¥ÕÅͼƬ´óСÓÐÏÞÖÆ£¬¼´¿ÉдÔÚÕâ¸öÀ¹½ØÆ÷ÖУ¬µ±Óû§Ñ¡Ôñ¹ý´óͼƬʱ¿ÉÒÔÌáʾ²¢ÇÒ¹ýÂË
forResult(int requestCode)´ò¿ªÍ¼Æ¬Ñ¡ÔñÆ÷£¬²¢ÇÒ´«ÈërequestCode

»ñÈ¡½á¹û

ÔÚµ÷ÓÃͼƬѡÔñÆ÷µÄFragment»òÕßActivityÖÐ

@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE_IMAGE) {
      final ArrayList<String> pathList =
          data.getStringArrayListExtra(PhotoPickerActivity.EXTRA_RESULT_SELECTION);
      final boolean original =
          data.getBooleanExtra(PhotoPickerActivity.EXTRA_RESULT_ORIGINAL, false);
    }
  }
已下载
0