Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.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
如何在android中保存裁剪图像而不是返回裁剪数据?_Android_Android Image - Fatal编程技术网

如何在android中保存裁剪图像而不是返回裁剪数据?

如何在android中保存裁剪图像而不是返回裁剪数据?,android,android-image,Android,Android Image,我有一个应用程序,我可以让用户选择一个画廊图像或用相机拍照,然后我给他选择裁剪它 现在,当用户裁剪图像时,Gallery裁剪器返回裁剪部分的数组,是否可以传递一个参数,要求Gallery裁剪器将输出保存到文件中(就像我在相机中开始拍摄图像时的情况一样) e、 g: 这是我使用的裁剪代码: // Initialize intent Intent intent = new Intent("com.android.camera.action.CROP"); // set data type to be

我有一个应用程序,我可以让用户选择一个画廊图像或用相机拍照,然后我给他选择裁剪它

现在,当用户裁剪图像时,Gallery裁剪器返回裁剪部分的数组,是否可以传递一个参数,要求Gallery裁剪器将输出保存到文件中(就像我在相机中开始拍摄图像时的情况一样)

e、 g:

这是我使用的裁剪代码:

// Initialize intent
Intent intent = new Intent("com.android.camera.action.CROP");
// set data type to be sent
intent.setType("image/*");

// get croppers available in the phone
List<ResolveInfo> list = getPackageManager().queryIntentActivities( intent, 0 );
int size = list.size();
// handle the case if there's no cropper in the phone
if (size == 0) {
    Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show();
    return;
} else {

// now this is the case if cropper exists
// initialize the Uri for the captures or gallery image

    Uri imageUri = Uri.fromFile(new File(mCurrentPhotoPath));

    // Send the Uri path to the cropper intent
    intent.setData(imageUri); 
    intent.putExtra("outputX", 200);
    intent.putExtra("outputY", 200);
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);         
    intent.putExtra("scale", true);
    // Here's my attempt to ask the intent to save output data as file
    File f = null;
    // Here I initialize empty file 
    try{
            // This returns the file created
        f = setUpCroppedFile();
        mCurrentThumbPath = f.getAbsolutePath();            
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));            
        intent.putExtra("output", Uri.fromFile(f));         
    }
    catch(IOException e){
        e.printStackTrace();
    }
    // --------------------------------------------------------------------
    // -----------> When changing this to false it worked <----------------
    // --------------------------------------------------------------------        
    intent.putExtra("return-data", true);
    // --------------------------------------------------------------------
    // --------------------------------------------------------------------

    // If there's only 1 Cropper in the phone (e.g. Gallery )
    if (size == 1) {
            // get the cropper intent found
            Intent i        = new Intent(intent);
            ResolveInfo res = list.get(0);

            i.setComponent( new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

            startActivityForResult(i, CROPPED_PHOTO);
    }

   // Please ignore the case if there are more . . I know how to handle it 
//初始化意图
Intent Intent=newintent(“com.android.camera.action.CROP”);
//设置要发送的数据类型
intent.setType(“image/*”);
//在手机中获取可用的裁剪器
List List=getPackageManager().queryInputActivities(intent,0);
int size=list.size();
//如果电话里没有窃听器,就处理这个案子
如果(大小==0){
Toast.makeText(这是“找不到图像裁剪应用程序”,Toast.LENGTH_SHORT.show();
返回;
}否则{
//现在,如果存在裁剪器,情况就是这样
//初始化捕获或库图像的Uri
uriimageuri=Uri.fromFile(新文件(mcurrentprotopath));
//将Uri路径发送到裁剪器
intent.setData(imageUri);
意向。额外(“输出”,200);
意向。额外投入(“产出”,200);
intent.putExtra(“aspectX”,1);
意图.putExtra(“aspectY”,1);
意图。putExtra(“比例”,真实);
//下面是我试图询问将输出数据保存为文件的意图
文件f=null;
//这里我初始化空文件
试一试{
//这将返回创建的文件
f=设置裁剪文件();
mCurrentThumbPath=f.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_输出,Uri.fromFile(f));
intent.putExtra(“输出”,Uri.fromFile(f));
}
捕获(IOE异常){
e、 printStackTrace();
}
// --------------------------------------------------------------------

//------------->当将此更改为false时,它起作用了此代码是修改后的代码,它起作用了:

// Initialize intent
Intent intent = new Intent("com.android.camera.action.CROP");
// set data type to be sent
intent.setType("image/*");

// get croppers available in the phone
List<ResolveInfo> list = getPackageManager().queryIntentActivities( intent, 0 );
int size = list.size();
// handle the case if there's no cropper in the phone
if (size == 0) {
    Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show();
    return;
} else {

// now this is the case if cropper exists
// initialize the Uri for the captures or gallery image

    Uri imageUri = Uri.fromFile(new File(mCurrentPhotoPath));

    // Send the Uri path to the cropper intent
    intent.setData(imageUri); 
    intent.putExtra("outputX", 200);
    intent.putExtra("outputY", 200);
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);         
    intent.putExtra("scale", true);
    // Here's my attempt to ask the intent to save output data as file
    File f = null;
    // Here I initialize empty file 
    try{
            // This returns the file created
        f = setUpCroppedFile();
        mCurrentThumbPath = f.getAbsolutePath();            
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));            
        intent.putExtra("output", Uri.fromFile(f));         
    }
    catch(IOException e){
        e.printStackTrace();
    }
    // --------------------------------------------------------------------
    // -----------> When changing this to false it worked <----------------
    // --------------------------------------------------------------------        
    intent.putExtra("return-data", false);
    // --------------------------------------------------------------------
    // --------------------------------------------------------------------

    // If there's only 1 Cropper in the phone (e.g. Gallery )
    if (size == 1) {
            // get the cropper intent found
            Intent i        = new Intent(intent);
            ResolveInfo res = list.get(0);

            i.setComponent( new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

            startActivityForResult(i, CROPPED_PHOTO);
    }

   // Please ignore the case if there are more . . I know how to handle it 
//初始化意图
Intent Intent=newintent(“com.android.camera.action.CROP”);
//设置要发送的数据类型
intent.setType(“image/*”);
//在手机中获取可用的裁剪器
List List=getPackageManager().queryInputActivities(intent,0);
int size=list.size();
//如果电话里没有窃听器,就处理这个案子
如果(大小==0){
Toast.makeText(这是“找不到图像裁剪应用程序”,Toast.LENGTH_SHORT.show();
返回;
}否则{
//现在,如果存在裁剪器,情况就是这样
//初始化捕获或库图像的Uri
uriimageuri=Uri.fromFile(新文件(mcurrentprotopath));
//将Uri路径发送到裁剪器
intent.setData(imageUri);
意向。额外(“输出”,200);
意向。额外投入(“产出”,200);
intent.putExtra(“aspectX”,1);
意图.putExtra(“aspectY”,1);
意图。putExtra(“比例”,真实);
//下面是我试图询问将输出数据保存为文件的意图
文件f=null;
//这里我初始化空文件
试一试{
//这将返回创建的文件
f=设置裁剪文件();
mCurrentThumbPath=f.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_输出,Uri.fromFile(f));
intent.putExtra(“输出”,Uri.fromFile(f));
}
捕获(IOE异常){
e、 printStackTrace();
}
// --------------------------------------------------------------------

//------------->将此更改为false时,它起作用了35; Shehbix@error setupcropedfile()在哪里方法我可以得到它的代码吗?因为我也面临同样的问题problem@VikrantAlekar很抱歉,我不再有这段代码,这是一个项目的过渡版本,但就我记忆所及,它只是创建一个文件并返回一个句柄,类似这样:没关系,我得到了我的解决方案n thnks以供回复