java– 具有多个选项的Android意图,即从gallary中选择图像并使用前置摄像头捕获图像

java– 具有多个选项的Android意图,即从gallary中选择图像并使用前置摄像头捕获图像,第1张

概述选择/捕获图像后,我需要裁剪图像.我已经完成了这一个.但问题是当我切换到Android最新版本(kitkat)时,作物意图不能正常工作.我的守则privatevoidpicPhoto(){IntentpickIntent=newIntent();if(Build.VERSION.SDK_INT<19){pickIntent.setType(

选择/捕获图像后,我需要裁剪图像.

我已经完成了这一个.但问题是当我切换到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中选择图像并使用前置摄像头捕获图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1101758.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存