gpt4 book ai didi

java.io.FileNotFoundException :/mnt/sdcard/1358731920220. jpg(没有这样的文件或目录)

转载 作者:行者123 更新时间:2023-12-02 07:19:38 24 4
gpt4 key购买 nike

public class BeginTakePhotoScene extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_begin_take_photo_scene);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

takephotobtn = new ImageButton(this);
takephotobtn.setId(888);
takephotobtn.setBackgroundResource(R.drawable.take_photo_btn);
takephotobtnparam = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
takephotobtnparam.addRule(RelativeLayout.CENTER_HORIZONTAL);
takephotobtnparam.topMargin = margin.heightPixels * 9 / 10 - height;
takephotobtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mUri = Uri.fromFile(new File(Environment
.getExternalStorageDirectory(), String.valueOf(System
.currentTimeMillis()) + ".jpg"));
camera.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);
camera.putExtra("return-data", false);
startActivityForResult(camera, PICTURE_RESULT);
}
});

choosephotobtn = new ImageButton(this);
choosephotobtn.setId(889);
choosephotobtn.setBackgroundResource(R.drawable.choose_photo_btn);
choosephotobtnparam = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
choosephotobtnparam.addRule(RelativeLayout.CENTER_HORIZONTAL);
choosephotobtnparam.addRule(RelativeLayout.BELOW, 888);
choosephotobtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Select Picture"),
SELECT_PICTURE);
}
});
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {

if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
selectedImageUri = data.getData();
uncroppedimage = getFilePath(selectedImageUri);

Intent cropIntent = new Intent("com.android.camera.action.CROP");

cropIntent.setDataAndType(selectedImageUri, "image/*");

cropIntent.putExtra("crop", "true");

cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);

cropIntent.putExtra("outputX", 128);
cropIntent.putExtra("outputY", 128);

File tempFile;
tempFile = new File(Environment.getExternalStorageDirectory(),
String.valueOf(System.currentTimeMillis()) + ".jpg");
mSavedUri = Uri.fromFile(tempFile);
cropIntent.putExtra("output", mSavedUri);

cropIntent.putExtra("return-data", true);

startActivityForResult(cropIntent, PIC_CROP);

} else if (requestCode == PICTURE_RESULT) {
Log.e("mUri", mUri.getPath());
uncroppedimage = mUri.getPath();

Intent cropIntent = new Intent("com.android.camera.action.CROP");

cropIntent.setDataAndType(mUri, "image/*");

cropIntent.putExtra("crop", "true");

cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);

cropIntent.putExtra("outputX", 128);
cropIntent.putExtra("outputY", 128);

File tempFile;
tempFile = new File(Environment.getExternalStorageDirectory(),
String.valueOf(System.currentTimeMillis()) + ".jpg");
mSavedUri = Uri.fromFile(tempFile);
cropIntent.putExtra("output", mSavedUri);

cropIntent.putExtra("return-data", true);

startActivityForResult(cropIntent, PIC_CROP);
} else {
Log.e("mSavedUri", mSavedUri.getPath());
profileimage.setImageURI(mSavedUri);
croppedimage = mSavedUri.getPath();

profileimage.setVisibility(View.VISIBLE);
confirmbtn.setVisibility(View.VISIBLE);

takephotobtnparam.topMargin = margin.heightPixels * 9 / 10
- height * 2;
}
}
}

private String getFilePath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = this.managedQuery(uri, projection, null, null, null);
if (cursor != null) {
int colum_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(colum_index);
} else
return null;
}
}

我记录uri.getpath,它返回file:///mnt/sdcard/1358731920220.jpg。这个链接似乎有额外的/。但是,我不知道为什么会这样?

最佳答案

cropIntent.putExtra("返回数据", true);

更改为

cropIntent.putExtra("返回数据", false);

将裁剪后的图像保存到SD卡中。

关于java.io.FileNotFoundException :/mnt/sdcard/1358731920220. jpg(没有这样的文件或目录),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14431403/

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