01
|
package xiaosi.RoundConcer;
|
03
|
import android.app.Activity;
|
04
|
import android.graphics.Bitmap;
|
05
|
import android.graphics.Bitmap.Config;
|
06
|
import android.graphics.BitmapFactory;
|
07
|
import android.graphics.Canvas;
|
08
|
import android.graphics.Paint;
|
09
|
import android.graphics.PorterDuff.Mode;
|
10
|
import android.graphics.PorterDuffXfermode;
|
11
|
import android.graphics.Rect;
|
12
|
import android.graphics.RectF;
|
13
|
import android.os.Bundle;
|
14
|
import android.widget.ImageView;
|
16
|
public class RoundConcerActivity extends Activity
|
18
|
/**
Called when the activity is first created. */
|
19
|
private ImageView
roundImage = null ;
|
21
|
public void onCreate(Bundle
savedInstanceState)
|
23
|
super .onCreate(savedInstanceState);
|
24
|
setContentView(R.layout.main);
|
26
|
roundImage
= (ImageView)findViewById(R.id.roundconcer);
|
29
|
Bitmap
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.a);
|
30
|
roundImage.setImageBitmap(getRoundCornerImage(bitmap, 50 ));
|
33
|
public static Bitmap
getRoundCornerImage(Bitmap bitmap, int roundPixels)
|
36
|
Bitmap
roundConcerImage = Bitmap.createBitmap(bitmap.getWidth(),
|
37
|
bitmap.getHeight(),
Config.ARGB_8888);
|
39
|
Canvas
canvas = new Canvas(roundConcerImage);
|
41
|
Paint
paint = new Paint();
|
43
|
Rect
rect = new Rect( 0 , 0 ,
bitmap.getWidth(), bitmap.getHeight());
|
44
|
RectF
rectF = new RectF(rect);
|
46
|
paint.setAntiAlias( true );
|
48
|
canvas.drawRoundRect(rectF,
roundPixels, roundPixels, paint);
|
50
|
paint.setXfermode( new PorterDuffXfermode(Mode.SRC_IN));
|
52
|
canvas.drawBitmap(bitmap, null ,
rect, paint);
|
53
|
return roundConcerImage;
|