显示从文件路径的android图片浏览? [英] Show Image View from file path in android?

查看:559
本文介绍了显示从文件路径的android图片浏览?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用文件名不仅没有从资源ID来显示图像。

I need to show image by using File name only not from the Resource id.

     ImageView imgView=new ImageView(this);
     imgView.setBackgroundResource(R.drawable.img1);

我在绘制文件夹中的图像IMG1。我想表明的图像从文件如何做到这一点。

I have the image img1 in the drawable folder. I wish to show that image from the file how to do this.

推荐答案

Labeeb是正确的,为什么你需要使用路径设置的图像,如果你的资源的资源文件夹内已经铺设,

Labeeb is right about why you need to set image using path if your resources are already laying inside the resource folder ,

这样的路径只有在需要时你的图像存储在SD卡。

This kind of path is needed only when your images are stored in SD-Card .

请尝试以下code,从存储在SD卡内的文件中设置位图图像。

File imgFile = new  File("/sdcard/Images/test_image.jpg");

if(imgFile.exists()){

    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

    ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);

    myImage.setImageBitmap(myBitmap);

}

和包括在清单文件中此权限:

And include this permission in the manifest file:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

这篇关于显示从文件路径的android图片浏览?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆