2013-02-10 71 views
1

我有一個演示,首先從攝像頭拍攝圖像,而不是要求用戶裁剪圖像。在屏幕中間有一個矩形框,在4個面的邊界觸摸時顯示4個箭頭在面的中點根據用戶需要更改框的大小。因爲它是使用intent com.android.camera.action.CROP提供的內置機制。如何執行圓形圖像裁剪功能

我想做同樣的事情,但圓形window.Which圓形圖像。

有沒有人有過這種裁剪功能的經驗。 請幫我一把。

回答

1

看看這個功能... 這是你所需要的?

public Bitmap getCroppedBitmap(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()); 

paint.setAntiAlias(true); 
canvas.drawARGB(0, 0, 0, 0); 
paint.setColor(color); 
// canvas.drawRoundRect(rectF, roundPx, roundPx, paint); 
canvas.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, 
     bitmap.getWidth()/2, paint); 
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); 
canvas.drawBitmap(bitmap, rect, rect, paint); 
//Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false); 
//return _bmp; 
return output; 
} 

檢查此鏈接.. crop image

如果您使用的意圖..嘗試使用此

intent.setType("image/*"); 
    intent.putExtra("crop", "true"); 
    intent.putExtra("scale", scale); 
    intent.putExtra("return-data", return_data); 
    intent.putExtra("circleCrop", true); 
+0

它顯示我編譯時錯誤Mode.SRC_IN。 這個類可用於android 2.3嗎? – 2013-02-10 12:58:53

+0

我不確定..嘗試檢查2.3中的其他模式 – 2013-02-10 15:10:34