ImageLoder in Android development for image loading and caching
Image processing category:
package .imageloder_text; import ; import ; import ; import com.; import com..Md5FileNameGenerator; import com.; import com.; import com.; import com.; import com.; import com.; import com.; import com.; import com.; import ; /** * Created by admin on 2016/4/9. */ public class ImageLoading extends Application { @Override public void onCreate() { // TODO Auto-generated method stub (); ImageLoaderConfiguration config = new ( this) .memoryCacheExtraOptions(480, 800) // max width, max height, that is, the maximum length and width of each cache file saved .discCacheExtraOptions(480, 800, null) // Can slow ImageLoader, use it carefully (Better don't use // it)/Set the cache details, it is best not to set this .threadPoolSize(3) // The number of loads in the thread pool .threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache // implementation/You can implement it through your own memory cache .memoryCacheSize(2 * 1024 * 1024) .discCacheSize(50 * 1024 * 1024) .discCacheFileNameGenerator(new Md5FileNameGenerator()) // Encrypt the URI name when saved with MD5 .tasksProcessingOrder() .discCacheFileCount(100) // Number of cached files .discCache( new UnlimitedDiscCache(new File(Environment .getExternalStorageDirectory() + "/myApp/imgCache"))) // Custom cache path .defaultDisplayImageOptions(getDisplayOptions()) .imageDownloader( new BaseImageDownloader(this, 5 * 1000, 30 * 1000)) .writeDebugLogs() // Remove for release app .build();// Start building ().init(config); } private DisplayImageOptions getDisplayOptions() { DisplayImageOptions options; options = new () .showImageOnLoading(.ic_launcher) // Set the picture to display during download .showImageForEmptyUri(.ic_launcher)// Set the picture to be displayed when the picture Uri is empty or wrong .showImageOnFail(.ic_launcher) // Set the picture displayed during error during picture loading/decoding .cacheInMemory(true)// Set whether the downloaded image is cached in memory .cacheOnDisc(true)// Set whether the downloaded pictures are cached in the SD card .considerExifParams(true) // Whether to consider the EXIF parameters of JPEG image (rotate, flip) .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)// Set how the picture is displayed in encoding .bitmapConfig(.RGB_565)// Set the decoding type of the picture// // .delayBeforeLoading(int delayInMillis)//int // delayInMillis sets the delay time before download for you // Set the bitmap before adding the image to the cache // .preProcessor(BitmapProcessor preProcessor) .resetViewBeforeLoading(true)// Set whether the image is reset before downloading, reset .displayer(new RoundedBitmapDisplayer(20))// Whether to set it to rounded corners and what is the radian .displayer(new FadeInBitmapDisplayer(100))// Whether the animation time gradually enters after the image is loaded .build();// Build complete return options; } } package .imageloder_text; import ; import ; import ; import ; import ; import ; import com.; import com.; import com.; /** * 1. Universal-ImageLoader configuration * * 2. Use Universal-ImageLoader to load network and local pictures * * @author Administrator */ public class MainActivity extends Activity { private ImageLoader loader; private ImageView iv_img; @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_main); loader=();//Instantiate ImageLoder iv_img=(ImageView)findViewById(.iv_img); String url="file:///"+"Load local picture"; //Load the network image, the first parameter is the path// ("/uploads/user/494/988131_100.jpg?t=1419303093000",iv_img); ("/uploads/user/494/988131_100.jpg?t=1419303093000", iv_img, new ImageLoadingListener() { @Override public void onLoadingStarted(String s, View view) { ("info","Loading starts"); } @Override public void onLoadingFailed(String s, View view, FailReason failReason) { ("info","Loading failed"); } @Override public void onLoadingComplete(String s, View view, Bitmap bitmap) { ("info","Loaded"); } @Override public void onLoadingCancelled(String s, View view) { ("info","Load Cancel"); } }); } }
Related Articles
Android Studio implements the function of saving QQ password (detailed explanation of case code)
This article mainly introduces the function of saving QQ passwords in Android Studio. This article introduces you very detailed through the example code, which has certain reference value for your study or work. Friends who need it can refer to it.2020-03-03Android downloads the file to the specified directory implementation code
This article introduces the implementation method of downloading files to a specified directory through the example code to you. It is very good and has reference value. If you need it, please refer to it.2017-06-06Android perfect implementation, take pictures, select pictures, cut and other code sharing
This article shares with you two codes for Android implementation, taking photos, selecting pictures, tailoring, etc., which are all extracted from formal projects. They are very practical. Friends in need can refer to it.2016-01-01Detailed explanation of five examples of Android implementing timer
This article mainly introduces five methods to implement timers on Android. It is very good and has reference value. Friends who need it can refer to it.2017-02-02Detailed explanation of how to customize countdown controls using attribute animations on Android
Since the Android 3.0 version, the system has provided us with a brand new animation mode, property animation, which has very powerful functions. The following article mainly introduces relevant information about how to customize the countdown control using property animation on Android. Friends who need it can refer to it.2018-05-05Android uses socket for binary streaming data transmission
This article mainly introduces Android using socket for binary streaming data transmission. The example code is introduced in this article in detail, which has certain reference learning value for everyone's learning or work. Friends who need it, please learn with the editor below.2023-04-04Android ADT offline download steps
This article mainly introduces the relevant information on the offline download operation steps of Android ADT. Friends who need it can refer to it.2017-04-04Example of Android programming call infrared remote control function
This article mainly introduces Android programming to call infrared remote control functions, and analyzes the relevant component call and layout operation implementation techniques of Android infrared function in combination with examples. Friends who need it can refer to it2017-08-08Android OpenGLES2.0 isosceles right triangles and colored triangles (three)
This article mainly introduces Android OpenGLES2.0 isosceles right-angle triangles and colored triangles in detail, which have certain reference value. Interested friends can refer to it.2016-12-12Android uses Photoview to realize the left and right sliding and zooming of pictures
This article mainly introduces in detail to Android using Photoview to achieve left and right sliding and zooming of pictures, which has certain reference value. Interested friends can refer to it.2018-01-01