CircleBitmapDisplayer for Universal Image Loader

来源:互联网 发布:软件设计师参考书 编辑:程序博客网 时间:2024/05/20 12:21

circleBitmapDisplayer

I have written about RemoteImageView, an ImageView’s subclass to display image from url, in my previous post . But, I never use this view again :(. Universal Image Loaderhave replaced this task.

Universal Image Loader have more complete features to handle displaying image tasks. Many configuration available to conform our needs. It is currently used by many android apps.

One of it’s flexibilities is the ability to change it’s image appearance. There isdisplayer(BitmapDisplayer bitmapDisplayer) method to change display image behaviour.

BitmapDisplayer script can be located oncom.nostra13.universalimageloader.core.display package. In the current version (1.9.1), there are five classes available here, one interface and it’s implementations:

  • BitmapDisplayer (interface)
  • FadeInBitmapDisplayer
  • RoundedBitmapDisplayer
  • RoundedVignetteBitmapDisplayer
  • SimpleBitmapDisplayer

We can create our own BitmapDisplayer. We only need to implement BitmapDisplayer class and override display() method.

In this post, I want to share my BitmapDisplayer. I needed to display image in circle shape. So, I created CircleBitmapDisplayer.

I used PorterDuffXfermode to crop the image. You can read more about PorterDuffXfermode in this article. I also added optional parameter to create border around the image.

CircleBitmapDisplayer script:

Example 1:

Example 2 (with border):

ScreenShotCircleBitmapDisplayer

You can download complete source code here.

0 0