Android 安卓我想裁剪一幅500*500的图像,它可以在除三星以外的所有设备上运行

Android 安卓我想裁剪一幅500*500的图像,它可以在除三星以外的所有设备上运行,android,android-intent,crop,Android,Android Intent,Crop,作为标题,我想裁剪一幅尺寸为500*500的图像, 它适用于大多数设备(如htc、sonyerrison、motors等),但三星(Sii/Ace…)除外 事实上,三星设备可以在360*360上工作,但当我调整到500*500时 当我把 intent.putExtra("outputX", 500); intent.putExtra("outputY", 360); startActivityForResult(intent,PHOTORESOULT), 它不会返回到活动结果() 这是裁

作为标题,我想裁剪一幅尺寸为500*500的图像, 它适用于大多数设备(如htc、sonyerrison、motors等),但三星(Sii/Ace…)除外

事实上,三星设备可以在360*360上工作,但当我调整到500*500时

当我把

 intent.putExtra("outputX", 500);
 intent.putExtra("outputY", 360);
 startActivityForResult(intent,PHOTORESOULT),
它不会返回到活动结果()

这是裁剪代码,我确信在这个uri中有一个图像

    public void startPhotoZoom(Uri uri) {

             Bitmap bitmap =null;
    try {
        bitmap = MediaStore.Images.Media.getBitmap(
                this.getContentResolver(), uri);
        Log.v("cropImage","Heigh="+bitmap.getHeight()+" Width="+bitmap.getWidth());
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    int width=bitmap.getWidth();
    int height=bitmap.getHeight();

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, IMAGE_UNSPECIFIED);
    intent.putExtra("crop", "true");
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    if(width < 500 || height < 500){
        if(width <= height){
            intent.putExtra("outputX", width); 
            intent.putExtra("outputY", width);
            Log.v("cropImage","outputX="+width+" outputY="+width);
        }else{
            intent.putExtra("outputX", height); 
            intent.putExtra("outputY", height);
            Log.v("cropImage","outputX="+height+" outputY="+height);
        }
    }else{
        intent.putExtra("outputX", 360);
        intent.putExtra("outputY", 360);
    }

    intent.putExtra("noFaceDetection", true);
    intent.putExtra("scale", true);
    intent.putExtra("return-data", true);
    startActivityForResult(intent, PHOTORESOULT);
}
public void startPhotoZoom(Uri){
位图=空;
试一试{
位图=MediaStore.Images.Media.getBitmap(
此文件为.getContentResolver(),uri);
Log.v(“cropImage”、“Heigh=“+bitmap.getHeight()+”Width=“+bitmap.getWidth());
}catch(filenotfounde异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
int width=bitmap.getWidth();
int height=bitmap.getHeight();
Intent Intent=newintent(“com.android.camera.action.CROP”);
setDataAndType(uri,未指定图像);
意图。额外(“作物”、“真实”);
intent.putExtra(“aspectX”,1);
意图.putExtra(“aspectY”,1);
如果(宽度<500 | |高度<500){

如果(width我认为,裁剪后的图像太大了。请务必阅读logcat

我也遇到了同样的问题,太大的图像无法传递到onActivityResult,必须让裁剪后的图像保存到磁盘,然后分别加载

略去

 intent.putExtra("return-data", true);
设定

 Uri destination;
 // some code to retriev an valid Uri
 intent.putExtra(MediaStore.EXTRA_OUTPUT, destination);

相反,请确保Uri目标指向一个文件。

您可以这样更改,您将从onActivityResult()获得精确的裁剪图像


请标记下面的答案,因为它是正确的。另外,请查看:了解更多详细信息
intent.putExtra("return-data", false);