Achieve Results
function Description andorid-imagespickers is a picture selector (single/multiple selection), photo and crop selection. Easy to use, the function can be configured on its own, andorid-imagespickers itself does not enforce a binding of a imageloader, developers can be based on their own project to andorid-imagespickers configuration picture loader.
Perhaps some people will ask: the system does not have album selector, why do you have to do a picture selector, is it necessary? I told you it was necessary. , QQ and so on app they are all their own picture selector, and there is no direct adjustment system of the picture selector. Why did you do it? Let me summarize the points:
· The biggest problem is compatibility, mobile phone manufacturers so many, album software so many problems caused by various wonderful
· Some phones take pictures of inverted images (such as Samsung and Meizu)
· Get the bitmap or URI empty
· A very frequent occurrence of oom
· Multi-Select not supported
· Photo/Select picture/Crop depending on the use of a bit of trouble, plus the processing of some rotation, cutting, compression is more troublesome, the code is not enough.
· The system's image selection UI is not consistent with its own app style
· Some do not support picture rotation
· ....
Use this picture selector above questions you do not have to consider, is so capricious.
How to deployone: Crawl through Gradle
dependencies {}
Second: Add the following permissions in the Androidmanifest.xml
<!--permission to read data from SDcard--><uses-permission android:name= "Android.permission.READ_EXTERNAL_STORAGE"/> <!--permission to write data to SDcard--><uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
Three: Create a picture loader (where you can use different third-party picture loading frames as you like glide example below)
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); }}
Four: Configure Imageconfig UI View Configuration
Imageconfig imageconfig = new Imageconfig.builder (new Glideloader ()) //If above 4.4, the status bar color (default black) is modified . Steeptoolbarcolor (Getresources (). GetColor (R.color.blue)) //title background color (default black) . Titlebgcolor (Getresources (). GetColor (R.color.blue)) //Submit button Font Color (default white) . Titlesubmittextcolor (Getresources (). GetColor ( R.color.white) //Title color (default white). Titletextcolor (Getresources (). GetColor (R.color.white)) . Build ();
Multi-Select
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)) //Open multiple selection (the default is multiple selection) . Mutiselect () //Maximum number (default 9 photos)//multi-select . Mutiselectmaxsize (9) //Turn on the camera function (default off) . Showcamera () ///Selected picture path . PathList (path) //Picture path (default/temp/picture) that is stored after the photo is created automatically . FilePath ("/ Imageselector/pictures ") . Build (); Imageselector.open (Mainactivity.this, imageconfig); Turn on the picture selector
Radio
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)) //Open Radio (the default is multiple selection) . Singleselect () //Turn on the camera function (default off) . Showcamera () //Picture path after photo (default/temp/picture) (will be created automatically). FilePath ("/imageselector/pictures") . Build (); Imageselector.open (Mainactivity.this, Imageconfig); Turn on the picture selector
single 1:1 Convenient
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)) //( Default configuration: Off scale 1:1 output resolution 500*500) . Crop () //Open Radio (the default is multiple selection) . Singleselect ()/ / Turn on the camera function (default off) . Showcamera () //Picture path (default/temp/picture) that is stored after the photo is created (automatically) . FilePath ("/imageselector/ Pictures ") . Build (); Imageselector.open (Mainactivity.this, imageconfig); Turn on the picture selector
single-Selection customization
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)) //( Default configuration: Off scale 1:1 output resolution 500*500) . Crop (1, 2, +, +) //Open Radio (default is multiple selection) . Singleselect () //Turn on the camera function (default off) . Showcamera () //Picture path (default/temp/picture) that is stored after the photo is created (automatically) . FilePath ("/ Imageselector/pictures ") . Build (); Imageselector.open (Mainactivity.this, imageconfig); Turn on the picture selector
V: Gets an array of selected photo paths in Onactivityresult:
@Overrideprotected void Onactivityresult (int requestcode, int resultcode, Intent data) {Super.onactivityresult ( Requestcode, ResultCode, data); if (Requestcode = = Imageselector.image_request_code && ResultCode = = RESULT_OK && data = null) { //G ET Image Path List list<string> pathList = Data.getstringarraylistextra (imageselectoractivity.extra_result ); for (String path:pathlist) { log.i ("imagepathlist", Path);}}}
code Example:
public class Mainactivity extends Appcompatactivity {private Button btn1, btn2; Private TextView TV1; Private arraylist<string> Path = new arraylist<> (); public static final int request_code = 123; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); BTN1 = (Button) Findviewbyid (R.ID.BTN1); BTN2 = (Button) Findviewbyid (R.ID.BTN2); TV1 = (TextView) Findviewbyid (R.ID.TV1); Radio Btn1.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View V) {Imageconfig imageconfig = new Imageconfig.builder (new Glideloader ()) . Steeptoolbarcolor (Getresources (). GetColor (R.color.titleblue)). Titlebgcolor (Getresou RCEs (). GetColor (R.color.titleblue)). Titlesubmittextcolor (Getresources (). GetcoLor (R.color.white)). Titletextcolor (Getresources (). GetColor (R.color.white)) Turn on the radio (the default is multi-select) (Singleselect). Singleselect ()//.crop () Turn on the camera function (default on)//.showcamera (). Requestcode (Request_code) . build (); Imageselector.open (Mainactivity.this, imageconfig); } }); Multi-Select Btn2.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View V) {Imageconfig imageconfig = new Imageconfig.builder (//Glideloader can use its own cache library New Glideloader ())//If above 4.4, the status bar color (default black) is modified. steept Oolbarcolor (Getresources (). GetColor (R.color.titleblue))//Title background color (default black). t Itlebgcolor (GetresoUrces (). GetColor (R.color.titleblue))//Submit button Font color (default white). Titlesubmittextco Lor (Getresources (). GetColor (R.color.white))//Title color (default white). Titletextcolor (g Etresources (). GetColor (R.color.white))//Turn on multiple selection (default to Multi-select) (Singleselect for single) . Singleselect ()//Crop//.crop ()//maximum number of multiple selections (default 9 photos). Mutiselectmaxsize (9)//Selected picture path. PathList (Path )//Picture path (default/temp/picture) that is stored after the photo is taken. FilePath ("/temp") Turn on the camera function (default on). Showcamera (). Requestcode (Request_code) . build (); Imageselector.open (Mainactivity.this, imageconfig); } }); } @Override protected void OnacTivityresult (int requestcode, int resultcode, Intent data) {Super.onactivityresult (Requestcode, ResultCode, data); if (Requestcode = = Request_code && ResultCode = = RESULT_OK && data = null) {List<s tring> pathList = Data.getstringarraylistextra (Imageselectoractivity.extra_result); Tv1.settext (""); for (String path:pathlist) {tv1.append (path); } path.clear (); Path.addall (pathList); } }}
----------------------------------------------------------------------------------------------------------- ---------
View and get source code:
https://github.com/jaikydota/Andorid-ImagesPickers
----------------------------------------------------------------------------------------------------------- ---------
Statement
Welcome reprint, but please keep the original source of the article
Jaiky_, brother Jay.
Source: http://blog.csdn.net/jaikydota163/article/details/52098880
Android Practical view animation and Tool series nine: Beautiful picture selector, high-performance anti-crash image selection Tool