¡¤ÄúÏÖÔÚµÄλÖ㺠ÔÆÒíÍøÂç >> ÎÄÕÂÖÐÐÄ >> ÍøÕ¾½¨Éè >> appÈí¼þ¿ª·¢ >> Android¿ª·¢ >> dz̸̸Android ͼƬѡÔñÆ÷
ImageSelector ¼ò½é
Android×Ô¶¨ÒåÏà²á£¬ÊµÏÖÁËÅÄÕÕ¡¢Í¼Æ¬Ñ¡Ôñ£¨µ¥Ñ¡/¶àÑ¡£©¡¢ImageLoaderÎÞ°ó¶¨ ÈÎÓÉ¿ª·¢ÕßÑ¡Ôñ
https://github.com/YancyYe/ImageSelector
Demo
Download Apk
¸üÐÂÄÚÈÝ
UIÖظÄ
ËùÓй¦ÄÜ¿ÉÅäÖÃ
½â¾öOOMÇé¿ö
ͼƬÊÖ¶¯Ñ¡Ôñ
Ö§³ÖººÓïºÍÓ¢Óï
½Øͼչʾ
ʹÓÃ˵Ã÷
²½ÖèÒ»£º
ͨ¹ýGradleץȡ
dependencies { compile 'com.yancy.imageselector:imageselector:1.1.0' }
²½Öè¶þ£º
ÔÚ 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); } }
ÅäÖÃImageSelector
ImageConfig imageConfig = new ImageConfig.Builder(MainActivity.this , 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)) // ¿ªÆô¶àÑ¡ £¨Ä¬ÈÏΪ¶àÑ¡£© (µ¥Ñ¡ Ϊ singleSelect) .mutiSelect() // ¶àѡʱµÄ×î´óÊýÁ¿ £¨Ä¬ÈÏ 9 ÕÅ£© .mutiSelectMaxSize(9) // ÒÑÑ¡ÔñµÄͼƬ·¾¶ .pathList(path) // ÅÄÕÕºó´æ·ÅµÄͼƬ·¾¶£¨Ä¬ÈÏ /temp/picture£© .filePath("/ImageSelector/Pictures") // ¿ªÆôÅÄÕÕ¹¦ÄÜ £¨Ä¬ÈϹرգ© .showCamera() .build(); ImageSelector.open(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); } } }