如何从内部存储设置图像位图?我检查了我的代码和图像是内部存储的地方,但功能SetImageBitmap的问题有什么帮助吗?下面是我的代码,拍照将其保存到内部存储器中。
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if (resultCode == Activity.RESULT_OK) {
String filename=currentImagePath.substring(currentImagePath.lastIndexOf("/")+1);
imageView.setImageBitmap(BitmapFactory.decodeFile(filename));
}
}
}
public void takepicture() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = imageFile();
currentImagePath = photoFile.getAbsolutePath();
} catch (IOException ex) {
ex.fillInStackTrace();
}
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
@SuppressLint("SimpleDateFormat")
private File imageFile() throws IOException {
// Create an image file name
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(Constants.DEFAULT_DATETIME_FORMAT);
String imageFileName = DATE_FORMAT.format(new Date());
ContextWrapper cw = new ContextWrapper(getActivity());
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
FileOperations.checkDirectory(directory, false);
return File.createTempFile(imageFileName, ".jpg", directory);
}
}