2

Мне нужно картинку по адресу, вроде: /mnt/sdcard/img.jpg вставить в ImageView. Я пытаюсь сделать так:

File image = new File(path);
Bitmap bm = BitmapFactory.decodeFile(image.getAbsolutePath());
webView1.setImageBitmap(bm);

Я получаю путь к файлу из Галереи, но приложение не видит путь к файлу,пишит, что файл отсутствует . Но в файловом менеджере файл есть и в галереи тоже.

if (arg0 == button4){
    Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, 1);
}

Как я получаю путь:

private String UriToBit(Uri uri) {
    String[] proj = {MediaStore.Images.Media.DATA};
    Cursor cursor = managedQuery(uri, proj, null, null, null);
    int index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(index);
}

Я пробовал функцию UriToBit() проверить на try - catch, но всё прошло успешно.

1

1 ответ 1

1

А может прав не хватает: Manifest.permission?

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.