Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android图像裁剪正在缩小图像的大小_Java_Android_Image_Android Layout_Crop - Fatal编程技术网

Java Android图像裁剪正在缩小图像的大小

Java Android图像裁剪正在缩小图像的大小,java,android,image,android-layout,crop,Java,Android,Image,Android Layout,Crop,我需要从android手机图库中裁剪一张照片,然后编辑它。 照片的原始尺寸为3264*2448,在我1280*720的屏幕上显示为缩小图像。 当我裁剪它时,我得到的图像大小为185*139 我用于裁剪的代码是 Intent cropIntent = new Intent("com.android.camera.action.CROP"); cropIntent.setDataAndType(picUri, "image/*"); cropInten

我需要从android手机图库中裁剪一张照片,然后编辑它。 照片的原始尺寸为3264*2448,在我1280*720的屏幕上显示为缩小图像。 当我裁剪它时,我得到的图像大小为185*139

我用于裁剪的代码是

        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        cropIntent.setDataAndType(picUri, "image/*");
        cropIntent.putExtra("crop", "true");
        cropIntent.putExtra("return-data", true);
        startActivityForResult(cropIntent, PIC_CROP);
当我在imageView中显示裁剪后的图像时,它显示为更小的图像


我应该裁剪原始大小的图像,而不是缩小的版本。请你们中的任何一位指导我如何做到这一点好吗?

首先,您应该知道,跨设备兼容性不能依赖裁剪意图。(任何OEM都可以用自己的版本替换库存摄像头/多媒体资料应用程序)。撇开这一点不谈,我认为你缺少了一些额外的东西,这些东西应该是为了达到你想要的效果

// width & height are your desired width/height for the cropped result
cropIntent.putExtra("outputX", width);
cropIntent.putExtra("outputY", height);
cropIntent.putExtra("aspectX", width);
cropIntent.putExtra("aspectY", height);
cropIntent.putExtra("scaleUpIfNeeded", true);
尝试将这些添加到您的意图中,看看结果如何。

添加:

intent.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);
然后你可以得到一个没有缩小的图像文件。并使用此保存的文件,而不是:

Intent.getExtras().getParcelable("data")

忽略返回的位图。

请尝试此操作,我知道为时已晚,但可能会帮助他人

private void performCrop() {
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(mImageCaptureUri, "image/*");
    //set crop properties
    cropIntent.putExtra("crop", "true");
    //indicate aspect of desired crop
    cropIntent.putExtra("aspectX", 4);
    cropIntent.putExtra("aspectY", 3);
    //indicate output X and Y
    cropIntent.putExtra("outputX", 800);
    cropIntent.putExtra("outputY", 800);

File f = new File(Environment.getExternalStorageDirectory(),
        "/temporary_holder.jpg");
    try {
        f.createNewFile();
    } catch (IOException ex) {
    Log.e("io", ex.getMessage());  
    }

uri = Uri.fromFile(f);

  cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

    startActivityForResult(cropIntent, PIC_CROP);

} //respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
    //display an error message
    String errorMessage = "Your device doesn't support the crop action!";
    Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
    toast.show();
}
}
使您的OnActivity结果如下:-

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

     if (requestCode == PIC_CROP) {

              String filePath = Environment.getExternalStorageDirectory()
                    + "/temporary_holder.jpg";

            thumbnail = BitmapFactory.decodeFile(filePath);



                   //thumbnail =    BitmapFactory.decodeFile(filePath);
           //    Log.i("",String.valueOf(thumbnail.getHeight()));

                ImageView image = (ImageView) findViewById(R.id.pestImage);
                image.setImageBitmap(thumbnail);
                }
}

我添加了额外的
cropIntent.putExtra(“outputX”,480);cropIntent.putExtra(“outputY”,640);cropIntent.putExtra(“aspectX”,480);cropIntent.putExtra(“aspectY”,640);cropIntent.putExtra(“scaleupipfneed”,真)到裁剪意图。裁剪后返回的位图为139*185。在处理纵横比时,您应该始终使用最不常用的控制符。我面临相同的问题。。。你的问题解决了吗???+1。我已经给出了答案。请检查一下。