본문 바로가기

안드로이드 개발/개발팁

동그랗게 랜더링하기(비트맵)

동그랗게 랜더링하기(비트맵)

 

 

 

 

 m_ivPhoto.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
            int width = m_ivPhoto.getMeasuredWidth();
            int height = m_ivPhoto.getMeasuredHeight();
            
            

            if(bitmap != null) {
                bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
                bitmap =  getRoundedBitmap(bitmap, width, height);
                m_ivPhoto.setImageBitmap(bitmap);

 

 

 

 

 

 public static Bitmap getRoundedBitmap(Bitmap bitmap, int width, int height) {
        final Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(output);
        final int color     = Color.GRAY;
        final Paint paint   = new Paint();
        final Rect rect     = new Rect(0, 0, width, height);
        final RectF rectF   = new RectF(rect);

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawOval(rectF, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);

        bitmap.recycle();
        return output;
    }