2013-10-03 2 views
0

Я пытаюсь отобразить изображение из URI в ImageView. Я пробовал несколько вещей, но всегда получал ошибку «Не могу решить метод setImageUri (android.net.uri)».не может решить setImageUri

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); 
    } 
} 

ответ

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) {} 
    } 
} 
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); 
+0

Это не сработало. 'getContent' не может быть разрешен. – timkonieczny

Смежные вопросы