java – 具有多个选项的Android意图,即从gallary中选择图像并使用前置摄像头捕获图像
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 具有多个选项的Android意图,即从gallary中选择图像并使用前置摄像头捕获图像,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2940字,纯文字阅读大概需要5分钟。
内容图文
选择/捕获图像后,我需要裁剪图像.
我已经完成了这一个.但问题是当我切换到Android最新版本(kitkat)时,作物意图不能正常工作.
我的守则
private void picPhoto() {
Intent pickIntent = new Intent();
if (Build.VERSION.SDK_INT < 19) {
pickIntent.setType("image/jpeg");
pickIntent.setAction(Intent.ACTION_GET_CONTENT);
pickIntent.putExtra("crop", "true");
} else {
pickIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
pickIntent.addCategory(Intent.CATEGORY_OPENABLE);
pickIntent.setType("image/jpeg");
pickIntent.putExtra("crop", "true");
}
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, getFileDirectory());
takePhotoIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
String pickTitle = "Select or take a new Picture";
Intent chooserIntent = Intent.createChooser(pickIntent, pickTitle);
chooserIntent.putExtra
(
Intent.EXTRA_INITIAL_INTENTS,
new Intent[]{takePhotoIntent}
);
startActivityForResult(chooserIntent, PICK_IMAGE);
}
任何人都可以帮我一个例子吗?
解决方法:
我用这种方法裁剪了一张在kitkat上工作的图片
@Override
public void onActivityResult(int requestCode, int resultCode,
final Intent data) {
if (resultCode == Activity.RESULT_OK&&requestCode==1) {
performCrop(image_uri);
}
}
private void performCrop(Uri picUri) {
thePic = null;
// take care of exceptions
try {
// call the standard crop action intent (the user device may not
// support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
// // indicate aspect of desired crop
cropIntent.putExtra("aspectX", 2);
cropIntent.putExtra("aspectY", 1);
// // // indicate output X and Y
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, 3);
}
// respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
Toast toast = Toast.makeText(getActivity(),
"This device doesn't support the crop action!",
Toast.LENGTH_SHORT);
toast.show();
} catch (OutOfMemoryError e) {
System.out.println("out of memoryyy");
} catch (Exception e) {
Display display = getActivity().getWindowManager()
.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
// // indicate aspect of desired crop
cropIntent.putExtra("aspectX", 2);
cropIntent.putExtra("aspectY", 1);
// // indicate output X and Y
cropIntent.putExtra("outputX", width);
cropIntent.putExtra("outputY", 200);
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, 3);
}
}
内容总结
以上是互联网集市为您收集整理的java – 具有多个选项的Android意图,即从gallary中选择图像并使用前置摄像头捕获图像全部内容,希望文章能够帮你解决java – 具有多个选项的Android意图,即从gallary中选择图像并使用前置摄像头捕获图像所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。