Universal-Image-Loader源码阅读(30)-CircleBitmapDisplayer
来源:互联网 发布:电脑版淘宝找不到仓库 编辑:程序博客网 时间:2024/06/05 22:48
展示圆形图片。把原始图片剪切成圆形图片进行展示。
就是把图片转变成原型图片画在展示器中(ImageAware)。
源码:
/** * Can display bitmap cropped by a circle. This implementation works only with ImageViews wrapped * in ImageViewAware. * <br /> * If this implementation doesn't meet your needs then consider * <a href="https://github.com/vinc3m1/RoundedImageView">RoundedImageView</a> or * <a href="https://github.com/Pkmmte/CircularImageView">CircularImageView</a> projects for usage. * * @author Qualtagh, Sergey Tarasevich (nostra13[at]gmail[dot]com) * @since 1.9.5 */public class CircleBitmapDisplayer implements BitmapDisplayer {protected final Integer strokeColor;//边线颜色protected final float strokeWidth;//边线宽度public CircleBitmapDisplayer() {this(null);}public CircleBitmapDisplayer(Integer strokeColor) {this(strokeColor, 0);}public CircleBitmapDisplayer(Integer strokeColor, float strokeWidth) {this.strokeColor = strokeColor;this.strokeWidth = strokeWidth;}@Overridepublic void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {if (!(imageAware instanceof ImageViewAware)) {throw new IllegalArgumentException("ImageAware should wrap ImageView. ImageViewAware is expected.");}imageAware.setImageDrawable(new CircleDrawable(bitmap, strokeColor, strokeWidth));}public static class CircleDrawable extends Drawable {//圆形图片protected float radius;//整个图片半径protected final RectF mRect = new RectF();protected final RectF mBitmapRect;protected final BitmapShader bitmapShader;protected final Paint paint;//画图片protected final Paint strokePaint;//画边线protected final float strokeWidth;protected float strokeRadius;//不包括边框在内的图片半径public CircleDrawable(Bitmap bitmap, Integer strokeColor, float strokeWidth) {radius = Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2;bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);mBitmapRect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());paint = new Paint();paint.setAntiAlias(true);paint.setShader(bitmapShader);paint.setFilterBitmap(true);paint.setDither(true);if (strokeColor == null) {strokePaint = null;} else {strokePaint = new Paint();strokePaint.setStyle(Paint.Style.STROKE);strokePaint.setColor(strokeColor);strokePaint.setStrokeWidth(strokeWidth);strokePaint.setAntiAlias(true);}this.strokeWidth = strokeWidth;strokeRadius = radius - strokeWidth / 2;}@Overrideprotected void onBoundsChange(Rect bounds) {super.onBoundsChange(bounds);mRect.set(0, 0, bounds.width(), bounds.height());radius = Math.min(bounds.width(), bounds.height()) / 2;strokeRadius = radius - strokeWidth / 2;// Resize the original bitmap to fit the new boundMatrix shaderMatrix = new Matrix();shaderMatrix.setRectToRect(mBitmapRect, mRect, Matrix.ScaleToFit.FILL);bitmapShader.setLocalMatrix(shaderMatrix);}@Overridepublic void draw(Canvas canvas) {canvas.drawCircle(radius, radius, radius, paint);//画图if (strokePaint != null) {//画边线canvas.drawCircle(radius, radius, strokeRadius, strokePaint);}}@Overridepublic int getOpacity() {return PixelFormat.TRANSLUCENT;}@Overridepublic void setAlpha(int alpha) {paint.setAlpha(alpha);}@Overridepublic void setColorFilter(ColorFilter cf) {paint.setColorFilter(cf);}}}
0 0
- Universal-Image-Loader源码阅读(30)-CircleBitmapDisplayer
- CircleBitmapDisplayer for Universal Image Loader
- Universal-Image-Loader源码阅读(35)-
- 【Android框架】Android-universal-image-loader源码阅读(一)
- Universal-Image-Loader源码阅读(1)-开篇
- Universal-Image-Loader源码阅读(2)-utils/L
- Universal-Image-Loader源码阅读(3)-utils/IoUtils
- Universal-Image-Loader源码阅读(4)-utils/ImageSizeUtils
- Universal-Image-Loader源码阅读(5)-core/iamgeaware/ImageAware
- Universal-Image-Loader源码阅读(6)-core/imageaware/ViewAware
- Universal-Image-Loader源码阅读(7)-core/imageaware/ImageViewAware
- Universal-Image-Loader源码阅读(8)-core/imageaware/NonViewAware
- Universal-Image-Loader源码阅读(9)-utils/StorageUtils
- Universal-Image-Loader源码阅读(10)-utils/MemoryCacheUtils
- Universal-Image-loader源码阅读(11)-catche/MemoryCache
- Universal-Image-Loader源码阅读(12)-cache/BaseMemoryCache
- Universal-Image-Loader源码阅读(13)-cache/LimitedMemoryCache
- Universal-Image-Loader源码阅读(14)-memory/impl/WeakMemoryCache
- node.js配置
- 终于推开那扇门
- mybaits generator 重复生成xml
- [转]【坐在马桶上看算法】算法3:最常用的排序——快速排序--作者:ahalei
- 机房收费系统—结账
- Universal-Image-Loader源码阅读(30)-CircleBitmapDisplayer
- java学习笔记
- Material Design 入门(二)——CardView
- 1. Two Sum
- Lua学习笔记(一)
- pivot的用法
- 用matlab实时读取串口数据并动态显示曲线
- CSDN如何转载
- TextUtils的使用