我正在尝试拍照并将其保存到外部存储空间,然后我保存照片的路径以加载此照片以使用个人资料图片。
public void capture()
{
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File f = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
file = new File(f, "img_" + timeStamp+".jpg");
photoUri = FileProvider.getUriForFile(EditProfileActivity.this,
BuildConfig.APPLICATION_ID + ".provider",
file);
intent.putExtra("data", photoUri);
//Log.i("Pathfewffewf",file.getPath());
startActivityForResult(intent,0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0 && resultCode == RESULT_OK) {
if (data != null) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
Bitmap circleBitmap = Bitmap.createBitmap(photo.getWidth(), photo.getHeight(), Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(photo, TileMode.CLAMP, TileMode.CLAMP);
Paint paint = new Paint();
paint.setShader(shader);
paint.setAntiAlias(true);
Canvas c = new Canvas(circleBitmap);
c.drawCircle(photo.getWidth() / 2, photo.getHeight() / 2, photo.getWidth() / 2, paint);
imageView.setImageBitmap(circleBitmap);
}
}
然后我
Bitmap myBitmap = BitmapFactory.decodeFile(user.getmImage());
image.setImageBitmap(myBitmap);
我在保存图像时加上日志消息,当它加载图像时
04-25 01:24:40.869 24049-24049/assignment.csc214.project3 I/Pathfewffewf: /storage/emulated/0/Android/data/assignment.csc214.project3/files/Pictures/img_20180425_012440.jpg
04-25 01:24:40.984 24049-24065/assignment.csc214.project3 D/EGL_emulation: eglMakeCurrent: 0xa37f4b80: ver 2 0 (tinfo 0xa3794840)
04-25 01:24:44.146 24049-24049/assignment.csc214.project3 E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/Android/data/assignment.csc214.project3/files/Pictures/img_20180425_012440.jpg (No such file or directory)
它有相同的路径,但它说没有这样的文件或目录...... 我认为文件无法正常保存我应该做什么