http://stackoverflow.com/questions/10975710/how-to-set-a-border-to-an-imageview
setContentView(R.layout.activity_main);
ImageView image = (ImageView) findViewById(R.id.imageview);
Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.pic1);
final int BORDER_WIDTH = 3;
final int BORDER_COLOR = Color.BLACK;
Bitmap res = Bitmap.createBitmap(bMap.getWidth() + 2 * BORDER_WIDTH,
bMap.getHeight() + 2 * BORDER_WIDTH,
bMap.getConfig());
Canvas c = new Canvas(res);
Paint p = new Paint();
p.setColor(BORDER_COLOR);
c.drawRect(0, 0, res.getWidth(), res.getHeight(), p);
p = new Paint(Paint.FILTER_BITMAP_FLAG);
c.drawBitmap(bMap, BORDER_WIDTH, BORDER_WIDTH, p);
Matrix mat = new Matrix();
//mat.postRotate(350);
Bitmap bMapRotate = Bitmap.createBitmap(res, 0, 0, res.getWidth(), res.getHeight(), mat, true);
image.setImageBitmap(bMapRotate);
or
ImageView image = (ImageView) findViewById(R.id.imageview);
Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.pic1);
final int BORDER_WIDTH = 3;
final int BORDER_COLOR = Color.BLUE;
Bitmap res = Bitmap.createBitmap(bMap.getWidth(),
bMap.getHeight(),
bMap.getConfig());
Canvas c = new Canvas(res);
Paint p = new Paint(Paint.FILTER_BITMAP_FLAG);
c.drawBitmap(bMap, BORDER_WIDTH, BORDER_WIDTH, p);
p = new Paint();
p.setColor(BORDER_COLOR);
p.setStrokeWidth(10);
//c.drawRect(0, 0, res.getWidth(), res.getHeight(), p);
c.drawLine(0, 0, bMap.getWidth(), 0, p);
c.drawLine(0, 0, 0, bMap.getHeight(), p);
c.drawLine(bMap.getWidth(), 0, bMap.getWidth(), bMap.getHeight(), p);
c.drawLine(0, bMap.getHeight(), bMap.getWidth(), bMap.getHeight(), p);
Matrix mat = new Matrix();
//mat.postRotate(350);
Bitmap bMapRotate = Bitmap.createBitmap(res, 0, 0, res.getWidth(), res.getHeight(), mat, true);
image.setImageBitmap(bMapRotate);
'Android' 카테고리의 다른 글
Making a transparent layout which is added to another layout (0) | 2013.07.08 |
---|---|
RGB 컬러코드 int로 파싱하기 (0) | 2013.07.05 |
If you use RESULT_OK, onActivityResult() is not called. (0) | 2013.05.23 |
HOW TO DEBUG ANDROID WIDGETS (0) | 2013.05.18 |
Custom view 생성 (0) | 2013.05.17 |