简体   繁体   English

如何裁剪从Android的图库中挑选的照片?

[英]How to CROP a photo which picked from gallery in android?

I am trying to CROP a photo in android, but my temp-photo file always empty(0kb) although I had picked a photo from my gallery. 我正在尝试在android中裁剪照片,但是我的临时照片文件始终为空(0kb),尽管我从图库中选择了一张照片。

This is my code : 这是我的代码:

 File dir = new File(Environment.getExternalStorageDirectory(), "pictures/softtime");//save path
            if (!dir.exists()) {
                dir.mkdirs();
            }
            currentImageFile = new File(dir, System.currentTimeMillis()+".jpg");//path+filename 
            //Create if not exists
            if (!currentImageFile.exists()) {
                try {
                    currentImageFile.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            Intent intentGet = new Intent("android.intent.action.GET_CONTENT");   
            intentGet.setType("image/*");
            intentGet.putExtra("crop",true);
            intentGet.putExtra("scale",true);
            intentGet.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(currentImageFile));
            startActivityForResult(intentGet,CROP);

I have run this code at my phone , I found that There is a new file created after I pick a photo ,but the new file is empty (0kb). 我已经在手机上运行了此代码,发现选了一张照片后创建了一个新文件,但是新文件为空(0kb)。

what can i do ? 我能做什么 ?

Thank you everyone for help. 谢谢大家的帮助。

There is no requirement for ACTION_GET_CONTENT activities to support some undocumented crop extra. 不需要ACTION_GET_CONTENT活动来支持一些未记录的额外crop If you want to allow the user to crop an image, use an image cropping library . 如果要允许用户裁剪图像,请使用图像裁剪库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM