Picasso extension of Android image loading tool

In this article, let's continue to learn what extensions are provided in Picasso. A good framework must be highly extensible. I just have what you need.

Let's take a look at what extensions are provided?

Picasso adopts the builder mode internally, so we just look at the methods provided by the builder internal classes

1 defaultBitmapConfig(Bitmap.Config bitmapConfig)

Set the pixel format. The default format of Picasso is ARGB_ 8888, we know that using this value, a pixel occupies 4 bytes, and RGB can be used_ 565, which can save half of the memory overhead. Of course, there is a certain loss of image quality.

2 downloader(Downloader downloader)

The user-defined downloader defaults to okhttp. The specific implementation class is okhttpdownloader

3 executor(ExecutorService executorService)

The default implementation of thread pool is picassoexecutiorservice, which sets the core threads and the maximum number of threads according to different network conditions. The maximum is 4, the minimum is 1, and the default is 3

4 memoryCache(Cache memoryCache)

The default implementation of the caching strategy is lrucache. LRU (least recently unused algorithm) is still widely used in memory caching.

5 listener(Listener listener)

A callback event of failed image loading. The callback method is onimageloadfailed (Picasso, Picasso, URI, exception)

6 requestTransformer(RequestTransformer transformer)

The conversion of the request is performed before the request is submitted

7 addRequestHandler(RequestHandler requestHandler)

The source of custom loaded pictures is 7 by default, as follows:

ResourceRequestHandler ContactsPhotoRequestHandler MediaStoreRequestHandler ContentStreamRequestHandler AssetRequestHandler FileRequestHandler NetworkRequestHandler

The above methods are called as follows

There are also several customizable methods in requestcreator, which were not mentioned in the previous blog, and are listed here

1 config(Bitmap.Config config)

The effect is exactly the same as that of defaultbitmapconfig (bitmap. Config bitmapconfig) above. Both methods can be set. Defaultbitmapconfig (bitmap. Config. Rgb_565) tends to be set globally, while config (bitmap. Config. Rgb_565) is only effective for a single request

2 transform(Transformation transformation)

Image conversion. Generally, after we get the image, we can further convert it before display, such as some color processing, changing the shape and so on.

The above methods are called as follows

Well, here we have basically introduced the functions of Picasso. Next, we will learn the internal implementation from the perspective of source code.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>