[英]I want to crop an image and type was view in image. How can I crop an image from camera using this type of cropping?
1.Have an Activity with your CropImageView
in it's layout. 1,在布局中包含一个带有
CropImageView
的Activity
2.Start the camera activity with an Intent
with a startActivityForResult
to take the picture. 2.使用带有
startActivityForResult
的Intent
启动相机活动以拍照。
3.In the Activity, override onActivityResult
to take the picture bitmap and do `CropImageView.setImageBitmap(bitmap) and voila! 3.在Activity中,重写
onActivityResult
以获取图片位图并执行`CropImageView.setImageBitmap(bitmap)和瞧! Now you can crop it... 现在您可以裁剪了...
Have a look at this one for an example: Capture Image from Camera and Display in Activity 以这个为例: 从相机捕获图像并在活动中显示
Try out following code: 试用以下代码:
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);
following parameters play vital role: 以下参数起着至关重要的作用:
intent.putExtra("aspectX", 0);
intent.putExtra("aspectY", 0);
For more info: Android - Crop image taken from camera with resizable ,independant height and width of cropped area 有关更多信息: Android-通过可调整大小的,独立于裁剪区域的高度和宽度的相机拍摄图像
Have a xml file for your activity where you will display the original image in the main_imageview and add another imageview as child to the crop_main_layout having the crop rect image as src (9 patch image) 有一个适合您的活动的xml文件,您将在其中显示原始图像在main_imageview中,并将另一个图像视图作为子级添加到crop_main_layout中,并以scro rect图像作为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>
The crop rect image view can be a custom class deriving from Imageview which will handle all onTouchEvents and will provide resize/move functionality and once user selects the selection and presses Done on your crop screen, crop the image using the selected crop rect (custom crop rect image view bounds). 裁剪矩形图像视图可以是源自Imageview的自定义类,该类将处理所有onTouchEvents,并提供调整大小/移动功能,一旦用户选择了所选内容并按裁剪屏幕上的完成,就使用选定的裁剪矩形(自定义裁剪)裁剪图像矩形图像视图范围)。
Bitmap.createBitmap(currentBitmap, cropRect.left, cropRect.top, cropRect.width(), cropRect.height());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.