-1
我是非常新的android ..是否有可能在一個圓形的佈局動態修復圖像?我們可以使用xml代碼來做到這一點,如果是的話,你可以建議我如何編寫代碼? 在此先感謝。如何在圓形佈局中動態修復圖像?
我是非常新的android ..是否有可能在一個圓形的佈局動態修復圖像?我們可以使用xml代碼來做到這一點,如果是的話,你可以建議我如何編寫代碼? 在此先感謝。如何在圓形佈局中動態修復圖像?
這個調用用於圓形圖像位圖。
public class ImageHelper {
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;
}
}
如何調用該方法getRoundedCornerBitmap(),並在那裏我們可以聲明位圖圖像? – user3057567
只是傳遞圖像位圖和像素。 – kyogs
是啊,它爲我工作,但我無法將圖像完全放在佈局的中心。你能告訴我怎麼做嗎? – user3057567