0

我正在尝试在 ImageView 中显示来自 URI 的图像。我尝试了一些东西,但总是收到错误“无法解析方法 setImageUri(android.net.uri)”。

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_PIC_REQUEST) {
        Uri receiptUri = Uri.parse("/Kassenzettel/3.bmp");
        ImageView receiptImage = (ImageView) findViewById(R.id.result_image);
        receiptImage.setImageUri(receiptUri);
    }
}
4

2 回答 2

1

这对我有用:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_PIC_REQUEST) {
        ImageView receiptImage = (ImageView) findViewById(R.id.result_image);

        Uri receiptUri = Uri.parse("/Kassenzettel/3.bmp");

        try {
            InputStream inputStream = getContentResolver().openInputStream(receiptUri);
            Drawable drawable = Drawable.createFromStream(inputStream, null);
            receiptImage .setImageDrawable(drawable);
        } catch (FileNotFoundException e) {}
    }
}
于 2013-10-09T17:37:07.290 回答
0

尝试这个..

ImageView receiptImage = (ImageView) findViewById(R.id.result_image);
Uri receiptUri = Uri.parse("/Kassenzettel/3.bmp");
InputStream inputStream = (InputStream)receiptUri.getContent();
Drawable drawable = Drawable.createFromStream(inputStream, null);
receiptImage .setImageDrawable(drawable);
于 2013-10-03T15:18:37.500 回答