【发布时间】:2014-01-22 03:47:06
【问题描述】:
我已经开发了自己的相机应用程序进行强制配置,当我尝试在下一个显示是否保存的活动中显示捕获的图像时?
我无法获取我捕获并显示在我的 ImageView 上的图像。我绝对会通过正确的路径获得absPathUri。
代码 sn-ps:-
imgView = (ImageView)findViewById(R.id.picView);
Bundle b= getIntent().getExtras();
absPathUri = Uri.parse(b.getString("URI"));
Toast.makeText(getApplicationContext(), ""+absPathUri, Toast.LENGTH_SHORT).show();
if(absPathUri!=null)
{
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE));
imgView.setImageURI(absPathUri);
}
关于我无法设置 ImageView 的原因进一步深入,抛出 Null Pointer Exception,这是由于 File Not Found。如果应用程序处于调试模式,它会在 ImageView 上显示正确的图像。似乎 mediaStore 会刷新,直到调试成功。
File imgFile = new File(getPath(absPathUri));
Toast.makeText(getApplicationContext(), "ImageFile Exists"+imgFile.exists(), Toast.LENGTH_SHORT).show();
if(imgFile.exists())
{
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imgView.setImageBitmap(myBitmap);
}
public String getPath(Uri photoUri) {
String filePath = "";
if (photoUri != null) {
String[] filePathColumn = { MediaStore.Images.Media.DATA };
try
{
Cursor cursor = getContentResolver().query(photoUri,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
filePath = cursor.getString(columnIndex);
cursor.close();
}catch(Exception e)
{
Toast.makeText(getApplicationContext(), ""+e, Toast.LENGTH_SHORT).show();
}
}
return filePath;
}
尝试过的解决方案:-
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE));
谁能指导我在 ImageView 上显示图像时哪里出错了?
【问题讨论】:
标签: android uri android-camera android-imageview