android分辨率中的imageview

时间:2014-02-24 10:31:10

标签: android imageview geometry

我想知道如何在圆形视图中查看图像?!像instagram中的imageview或者像其他可以放置imageview的应用程序一样。事实上,我想通过以圆形或方形显示图像来控制。

2 个答案:

答案 0 :(得分:1)

只需查看以下代码

即可
 public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
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 = 12;

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;

}

答案 1 :(得分:0)

请参阅此答案here
并请五我一些反馈

希望能帮助。