答案 0 :(得分:0)
1.在CropImageView
的布局中进行活动
2.使用Intent
和startActivityForResult
启动相机活动以拍摄照片。
3.在Activity中,覆盖onActivityResult
以获取图片位图并执行`CropImageView.setImageBitmap(位图)并瞧!现在你可以裁剪它了......
看一下这个例子:
Capture Image from Camera and Display in Activity
答案 1 :(得分: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
答案 2 :(得分: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并提供调整大小/移动功能,一旦用户选择选择并在裁剪屏幕上按下完成,使用选定的裁剪矩裁剪图像(自定义裁剪矩形图像视图边界)。
Bitmap.createBitmap(currentBitmap, cropRect.left, cropRect.top, cropRect.width(), cropRect.height());