0
我們從我們的應用程序是這樣開始的相機應用:返回沒有得到顯示的ImageView
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String timeStamp = "001";
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MymhiImages");
imagesFolder.mkdirs();
File image = new File(imagesFolder, filename + ".png");
Uri uriSavedImage = Uri.fromFile(image);
,並試圖捕捉從相機這樣的回報:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
InputStream stream = null;
if (requestCode == REQUEST_CODE && resultCode == AppCompatActivity.RESULT_OK)
try {
// recyle unused bitmaps
if (bitmap != null) {
bitmap.recycle();
}
stream = getContentResolver().openInputStream(data.getData());
bitmap = BitmapFactory.decodeStream(stream);
imageView.setImageBitmap(bitmap);
File dir = new File(Environment.getExternalStorageDirectory().toString() + "/mhi/");
if (!dir.exists())
dir.mkdir();
String path = Environment.getExternalStorageDirectory().toString() + "/mhi/" + filename + ".png";
OutputStream out = null;
File imageFile = new File(path);
try {
out = new FileOutputStream(imageFile);
// choose JPEG format
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
} catch (FileNotFoundException e) {
// manage exception
} catch (IOException e) {
// manage exception
} finally {
try {
if (out != null) {
out.close();
//jsi.showMsg("Saved Successfully");
Toast.makeText(getApplicationContext(), "Saved Successfully", Toast.LENGTH_LONG).show();
}
} catch (Exception exc) {
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
if (stream != null)
try {
stream.close();
} catch (IOException ie) {
ie.printStackTrace();
}
}
}
原諒我們,如果代碼太多的話。
我們的問題是圖像被保存到磁盤,但不顯示在ImageView
。我們錯過了什麼?
http://stackoverflow.com/a/37614997/6067866 –