Developer/Android

[Android] ImageView Round처리하기.

블로blow 2010. 12. 16. 11:28
728x90

getRoundedCornerBitmap 클래스로 해주면 됩니다.


[##__##]



public class ImageRound extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        ImageView img = (ImageView)findViewById(R.id.image);

        Bitmap bm = BitmapFactory.decodeResource(getResources(), 

                R.drawable.icon);

        img.setImageBitmap(getRoundedCornerBitmap(bm, 10));

    }

    

    public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {

        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap

                .getHeight(), Config.ARGB_8888);

        Canvas canvas = new Canvas(output);


        final int color = 0xff424242;

        final Paint paint = new Paint();

        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

        final RectF rectF = new RectF(rect);

        final float roundPx = pixels;


        paint.setAntiAlias(true);

        canvas.drawARGB(0, 0, 0, 0);

        paint.setColor(color);

        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);


        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));

        canvas.drawBitmap(bitmap, rect, rect, paint);


        return output;

    }

}

728x90