2015-11-03 45 views
2

我如何裁剪圖像?我已經嘗試了一些使用意圖的概念,但仍然失敗..我想要這種類型的裁剪。我想剪裁圖像,並在圖像中查看類型。我如何從相機使用這種類型的裁剪裁剪圖像?

這是圖像[http://i.stack.imgur.com/o6OuZ.png]

+0

請問您具體嗎? –

+0

我只是想裁剪圖像就像上面顯示link.there有8個點的裁剪,我想調整從這個點的裁剪點。我使用CropImageview庫,但無法裁剪圖像。 –

+0

https://github.com/cesards/CropImageView這裏是一個鏈接,我可以使用庫。 –

回答

0

1.在您的佈局中與您的CropImageView進行一次活動。
2.使用和startActivityForResult拍攝照片,開始相機活動。
3.在活動中,覆蓋onActivityResult拍攝照片位圖並執行`CropImageView.setImageBitmap(bitmap)和瞧!現在你可以裁剪...
看一看這一個例子: Capture Image from Camera and Display in Activity

0

試試下面的代碼:

BitmapFactory.Options opts = new BitmapFactory.Options(); 
opts.inSampleSize = 1; 
Bitmap bm = BitmapFactory.decodeFile(imagePath, opts); 
Intent intent = new Intent("com.android.camera.action.CROP");    
intent .setDataAndType(outputFileUri, "image/*"); 
intent.putExtra("outputX",bm.getWidth()); 
intent.putExtra("outputY", bm.getHeight()); 
intent.putExtra("aspectX", 0); 
intent.putExtra("aspectY", 0); 
intent.putExtra("scale", true); 
intent.putExtra("return-data", false); 
startActivityForResult(intent, 2); 

以下參數起到至關重要的作用:

intent.putExtra("aspectX", 0); 
    intent.putExtra("aspectY", 0); 

欲瞭解更多信息: Android - Crop image taken from camera with resizable ,independant height and width of cropped area

+0

這種類型的作物圖像我已經完成了,我想要在que中查看的那種類型的裁剪。看到感謝您的建議 –

0

有一個xml文件您的活動,您將顯示在main_imageview原始圖像和爲孩子添加其他的ImageView到crop_main_layout具有裁剪矩形圖像SRC(9修補圖像)

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/crop_main_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:id="@+id/imageview_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" > 
     <ImageView 
      android:id="@+id/main_imageview" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@color/transparent" 
      android:scaleType="centerInside" 
      android:padding="@dimen/crop_view_padding"/> 
    </LinearLayout> 
</RelativeLayout> 

作物矩形圖像視圖可以是自定義類從Imageview派生出來,它將處理所有onTouchEvents,並提供調整大小/移動功能,一旦用戶選擇了選擇並在裁剪屏幕上按下Done,使用選定的裁切矩形(自定義裁切矩形圖視圖邊界)裁剪圖像。

Bitmap.createBitmap(currentBitmap, cropRect.left, cropRect.top, cropRect.width(), cropRect.height());