对于Android的裁剪图像preVIEW例子 [英] android image preview example for cropping

查看:297
本文介绍了对于Android的裁剪图像preVIEW例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多应用,如Facebook,有这个功能,其中后一个用户选择从他们的设备的画廊图像,用户再运到preVIEW在那里他们可以选择自己的形象的一个播种的版本。通过SO(例如<一细算href=\"http://stackoverflow.com/questions/11626869/how-to-crop-image-on-camera-$p$pview-goggles-style-android\">How在摄像头preVIEW&QUOT作物图像;护目镜风格&QUOT; - Android的),我发现的此链接方式的例子,但压缩似乎是销售(相机preview.zip )。由于该职位是有点老了,我想知道,如果有人知道另一个例子在那里,或者如果他们知道该怎么做,请分享你的知识。谢谢你。

Many apps, such as Facebook, have this feature where after a user chooses an image from their device's gallery, the user is then brought to a preview where they can choose a cropped version of their image. After looking through SO (e.g. How to crop image on camera preview "Goggles style" - Android), I found this link to a an example, but the zip seems to be for sale (CameraPreview.zip). Since that post is a bit old, I was wondering if someone is aware of another example out there or if they know how to do it, please share your knowledge. Thanks.

推荐答案

试试下面的code,更改参数按您的要求:

Try the below code, change the parameters as per your requirements:

Intent cropIntent = new Intent("com.android.camera.action.CROP");
//indicate image type and Uri
cropIntent.setDataAndType(fileUri, "image/*");
//set crop properties
//cropIntent.putExtra("crop", "true");
//indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);

//indicate output X and Y
cropIntent.putExtra("outputX", 350);
cropIntent.putExtra("outputY", 350);
//retrieve data on return
//cropIntent.putExtra("return-data", true);
// some code to retriev an valid Uri
cropUri =  Uri.fromFile(getOutputMediaFile(MEDIA_TYPE_IMAGE));
 cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, cropUri);
//start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, CROP_REQ_CODE);

和可以使用的onActivityResult得到输出()

and you can get the output using in OnActivityResult()

Bundle extras = data.getExtras();
//get the cropped bitmap
clickedPhoto = extras.getParcelable("data");

这篇关于对于Android的裁剪图像preVIEW例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆