Browse Source

Merge branch 'master' of http://192.168.1.5:3000/BWPB3/ytzh_Android

# Conflicts:
#	app/src/main/res/values/strings.xml
developer
zhanghui 8 years ago
parent
commit
d924b4a318
1 changed files with 71 additions and 0 deletions
  1. +71
    -0
      app/src/main/java/com/qhclh/ytzh/utils/widget/XCRoundImageView.java

+ 71
- 0
app/src/main/java/com/qhclh/ytzh/utils/widget/XCRoundImageView.java View File

@ -0,0 +1,71 @@
package com.qhclh.ytzh.utils.widget;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ImageView;
/**
* Created by ZH on 2017/11/30.
*/
public class XCRoundImageView extends ImageView{
private Paint paint;
public XCRoundImageView(Context context) {
super(context);
}
public XCRoundImageView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public XCRoundImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
paint=new Paint();
}
@Override
protected void onDraw(Canvas canvas) {
Drawable drawable = getDrawable();
if (null != drawable) {
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
Bitmap b = getCircleBitmap(bitmap, 14);
final Rect rectSrc = new Rect(0, 0, b.getWidth(), b.getHeight());
final Rect rectDest = new Rect(0,0,getWidth(),getHeight());
paint.reset();
canvas.drawBitmap(b, rectSrc, rectDest, paint);
} else {
super.onDraw(canvas);
}
}
private Bitmap getCircleBitmap(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
int x = bitmap.getWidth();
canvas.drawCircle(x / 2, x / 2, x / 2, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
}

Loading…
Cancel
Save