Android getBitmap 找不到指定的图像
Android getBitmap can't find the specified image
我试图在使用相机的 PictureCallback 后检索存储在我的存储器中的图像,但是 getBitmap 方法似乎无法找到该图像,它 returns 出现以下错误:
java.io.FileNotFoundException: No content provider:
file://storage/emulated/0/MyApp/IMG_20150903_154338.jpg
我向你保证,该图像在该位置可用。我检查了位置。
Take the Photo
Get the image through the callback
Display the image in an ImageView
图像已保存。不显示。
这是我的代码:
captureImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mCamera.takePicture(null, null, new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File storageDir = new File(Environment.getExternalStorageDirectory() + "/", "MyApp");
if (!storageDir.exists()) {
storageDir.mkdirs();//directory created
}
// get the current timestamp
String timest = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
//Create your picture file
File pictureFile;
pictureFile = new File(storageDir.getPath() + File.separator + "IMG_" + timest + ".jpg");
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (Exception e) {
Log.d("MyApp", e.toString());
}
Uri uri = Uri.fromFile(pictureFile);
try {
Bitmap bmp = MediaStore.Images.Media.getBitmap(CameraActivity.this.getContentResolver() , Uri.parse("file://"+ storageDir.getPath() + File.separator + "IMG_" + timest + ".jpg"));
imageViewer = (ImageView) findViewById(R.id.imageViewer);
imageViewer.setImageBitmap(bmp);
} catch (Exception e) {
Log.d("MyApp", e.toString());
}
您是否已将读取外部存储的权限添加到您的androidmanifest.xml?
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
我试图在使用相机的 PictureCallback 后检索存储在我的存储器中的图像,但是 getBitmap 方法似乎无法找到该图像,它 returns 出现以下错误:
java.io.FileNotFoundException: No content provider: file://storage/emulated/0/MyApp/IMG_20150903_154338.jpg
我向你保证,该图像在该位置可用。我检查了位置。
Take the Photo
Get the image through the callback
Display the image in an ImageView
图像已保存。不显示。
这是我的代码:
captureImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mCamera.takePicture(null, null, new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File storageDir = new File(Environment.getExternalStorageDirectory() + "/", "MyApp");
if (!storageDir.exists()) {
storageDir.mkdirs();//directory created
}
// get the current timestamp
String timest = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
//Create your picture file
File pictureFile;
pictureFile = new File(storageDir.getPath() + File.separator + "IMG_" + timest + ".jpg");
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (Exception e) {
Log.d("MyApp", e.toString());
}
Uri uri = Uri.fromFile(pictureFile);
try {
Bitmap bmp = MediaStore.Images.Media.getBitmap(CameraActivity.this.getContentResolver() , Uri.parse("file://"+ storageDir.getPath() + File.separator + "IMG_" + timest + ".jpg"));
imageViewer = (ImageView) findViewById(R.id.imageViewer);
imageViewer.setImageBitmap(bmp);
} catch (Exception e) {
Log.d("MyApp", e.toString());
}
您是否已将读取外部存储的权限添加到您的androidmanifest.xml?
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>