2014-02-24 75 views
-1

我想知道如何在圓形視圖中查看圖像?!就像Instagram中的imageview或者其他可以放置imageview的應用程序一樣。實際上,我想通過在圓形或正方形中顯示圖像來進行控制。在android分辨率的imageview

+0

你有沒有嘗試過任何東西? –

+0

哦,那真棒! thanx body – user3077582

回答

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; 

}

+0

你能告訴我我準確把這段代碼放在哪裏嗎?我的意思是我想從手機上打開一張圖片並選擇它,之後我想要一個特定尺寸的圖像視圖,如果它不是我裁剪它,之後它會以圓形視圖顯示它。希望沒有它太多:) – user3077582

0

請參考此答案here
並請5我一些反饋

希望幫助。