2016-08-22 20 views
0

代碼即時通訊使用:createBitmap簡單作物的Android

Bitmap cropImg = Bitmap.createBitmap(bitmap, cropW, cropH, newWidth, newHeight); 

不是Java程序員,但據我所知它的一切是從左上方。

我的尺寸

cropW: '696', 
cropH: '72', 
newWidth: '1200', 
newHeight:'1800', 

但我最終圖像的左上角..

我真的想會是這樣給它4點,它取出圖像中間。

我使用這個作爲插件Cordova/Phonegap,如果它有所作爲。

任何幫助或解釋都會有幫助。

感謝

回答

0

使用以下功能

public Bitmap getCircleBitmap(Bitmap bm) { 

    int sice = Math.min((bm.getWidth()), (bm.getHeight())); 

    Bitmap bitmap = ThumbnailUtils.extractThumbnail(bm, sice, sice); 

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); 

    Canvas canvas = new Canvas(output); 


    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); 

    paint.setAntiAlias(true); 
    paint.setDither(true); 
    paint.setFilterBitmap(true); 
    paint.setColor(color); 
    canvas.drawARGB(0, 0, 0, 0); 

    canvas.drawOval(rectF, paint); 
    //canvas.drawCircle(50, 50, 50, paint); 
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); 
    canvas.drawBitmap(bitmap, rect, rect, paint); 

return output; 

}

+0

有很多周圍的裁剪選擇黑色區域,我怎麼擺脫那個的。謝謝 –