1

我无法显示使用 3rd 方 android 应用程序捕获的当前图像并将其显示在我自己的本机应用程序上。它总是一个只有操作栏的空屏幕。但是,拍摄的照片可能位于我指定的文件夹中。

有人可以帮忙吗?非常感激!干杯:)

XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:id="@+id/linear">

  <ImageView android:id="@+id/imageView1"
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:contentDescription="@string/desc"/>
</LinearLayout>

源代码:

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    switch(requestCode) {
    case 0:
        if(resultCode == Activity.RESULT_OK){  
            Bitmap photo = (Bitmap) data.getExtras().get("data"); 
            imageView.setImageBitmap(photo);
        }
    break; 

    case 1:
        if(resultCode == RESULT_OK){  
            Uri selectedImage = data.getData();
            imageView.setImageURI(selectedImage);
        }
    break;

    }
  }
}
4

2 回答 2

0
android:contentDescription="@string/desc"

将上面的行添加到 ImageView 的 xml 中,其中 desc 应该在 string.xml 中并将其设置为某个值。看起来这定义了简要描述视图内容的文本。此属性主要用于可访问性。由于某些视图没有文本表示,因此此属性可用于提供此类。

像 ImageViews 和 ImageButtons 这样的非文本小部件应该使用 contentDescription 属性来指定小部件的文本描述,以便屏幕阅读器和其他辅助工具可以充分描述用户界面。

String  selectedImagePath = getPath(selectedImageUri);
Bitmap myBitmap = BitmapFactory.decodeFile(selectedImagePath);
imageView.setImageBitmap(bmp);

使用上面的代码

public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}
于 2012-10-18T10:47:11.647 回答
0

你在保存你的价值fileUriActivity?如果是这样,您是否从已保存的实例中恢复它?

如果不是,它可能会在活动被销毁时被重置。

于 2012-10-22T09:22:21.863 回答