java - Android图像裁剪正在减小图像的大小

标签 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/*");
        cropIntent.putExtra("crop", "true");
        cropIntent.putExtra("return-data", true);
        startActivityForResult(cropIntent, PIC_CROP);

当我在 imageView 中显示裁剪后的图像时,它显示为一个小得多的图像。

我应该裁剪原始大小的图像而不是缩小后的版本。你们中的任何人都可以指导我如何执行此操作吗?

最佳答案

请试试这个,我知道为时已晚,但可能会对某人有所帮助。

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();
}
}

让你的 onActivityResult 像这样:-

    @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);
                }
}

关于java - Android图像裁剪正在减小图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14385188/

相关文章:

html - 使用css将图像任意放置在另一个图像上

java - 在 Java 中从 Optional->List->List 转换的链方法

java - 在 Activity 之间来回传递数据

java - 从服务中连续运行的线程发布通知

android - Firebase 实时数据库未在 Android 调试 APK 版本上返回所有值

jquery - 将多个图像(带标题)对齐到基线,所有不同的高度

java - 如何获取 5x5 正方形的 RGB 值?

java - 如何将一维数组的元素打印到 N x N 框中

java - 将列名更改为其他时,TableView提供错误

android - 如何检测错误?