gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:16:12 25 4
gpt4 key购买 nike

我需要从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com