如何在图像视图中设置图像,android

发布于 2024-11-05 05:01:45 字数 1645 浏览 1 评论 0原文

您好,我想显示 SD 卡中的图像。我有 10 张图片。其中我可以显示 9 张图像,但 1 张图像无法在图像视图中显示。

我的 SD 卡位置是正确的。我正在使用android编程。我得到的文件存在为真。另外,我得到的输入流不为空,但是当我想获取某些字段的可绘制对象时,我没有得到,但对于所有其他字段获取可绘制对象。

我也尝试过使用

iv1.setImageURI(Uri.parse(str1))

,但没有得到任何解决方案

以下是我的代码片段

InputStream is1 = getBitMapImage(str1);
        InputStream is2 = getBitMapImage(str2);
        InputStream is3 = getBitMapImage(str3);
        Drawable d1 = Drawable.createFromStream(is1, "first");
        Drawable d2 = Drawable.createFromStream(is2, "second");
        Drawable d3 = Drawable.createFromStream(is3, "third");

        iv1.setImageDrawable(d1);
        iv2.setImageDrawable(d2);
        iv3.setImageDrawable(d3);
        System.out.println(is1+"....d1...."+d1);
        System.out.println(is2+"....d2...."+d2);
        System.out.println(is3+"....d3...."+d3);


public static BufferedInputStream getBitMapImage(String filePath) {
        Log.e("Utilities", "Original path of image from Utilities "+filePath);

        File imageFile = null;
        FileInputStream fileInputStream = null;
        BufferedInputStream buf= null;
        try{

        imageFile= new File(filePath);
        System.out.println("Does Images File exist ..."+imageFile.exists());

        fileInputStream = new FileInputStream(filePath);


        buf = new BufferedInputStream(fileInputStream);

        }catch(Exception ex){

        }finally{
            try{

            imageFile = null;
            fileInputStream.reset();
            fileInputStream.close();
            }catch(Exception ex){}
        }

        return buf;
    }

Hi I want to show an image from SD card. I have 10 images. out of which i am able to show 9 images but 1 image i cannot show in image view.

My SD card location is correct. I am using android programming. I am getting file exists as true. also I am getting not null input stream but when I want to get Drawable object for some fiels i am not getting but for all others getting drawable object.

Also I have tried using

iv1.setImageURI(Uri.parse(str1))

but i didnot get any solution

Following is my code snippet

InputStream is1 = getBitMapImage(str1);
        InputStream is2 = getBitMapImage(str2);
        InputStream is3 = getBitMapImage(str3);
        Drawable d1 = Drawable.createFromStream(is1, "first");
        Drawable d2 = Drawable.createFromStream(is2, "second");
        Drawable d3 = Drawable.createFromStream(is3, "third");

        iv1.setImageDrawable(d1);
        iv2.setImageDrawable(d2);
        iv3.setImageDrawable(d3);
        System.out.println(is1+"....d1...."+d1);
        System.out.println(is2+"....d2...."+d2);
        System.out.println(is3+"....d3...."+d3);


public static BufferedInputStream getBitMapImage(String filePath) {
        Log.e("Utilities", "Original path of image from Utilities "+filePath);

        File imageFile = null;
        FileInputStream fileInputStream = null;
        BufferedInputStream buf= null;
        try{

        imageFile= new File(filePath);
        System.out.println("Does Images File exist ..."+imageFile.exists());

        fileInputStream = new FileInputStream(filePath);


        buf = new BufferedInputStream(fileInputStream);

        }catch(Exception ex){

        }finally{
            try{

            imageFile = null;
            fileInputStream.reset();
            fileInputStream.close();
            }catch(Exception ex){}
        }

        return buf;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那片花海 2024-11-12 05:01:45

某些图像文件无法共享。黑莓 rem 文件无法共享。如果直接存储,则无法打开该类型的文件。因此,在存储过程中将该文件转换为 .jpg 文件,然后只有您可以打开这些文件。为了检查目的,将文件从设备中拉出到系统中,然后使用 gimp 将其转换为 .jpg 文件并再次推送到设备中,然后尝试运行程序并检查图像文件是否显示在图像视图中。

谢谢
苏尼尔

Some image files cannot be shared. Blackbery rem file cannot be shared. That type of file cannot be opened if stored directly. So during storing convert that file into .jpg file and then only u can open those file. For checking purpose pullout your file from the device to your system then convert in into .jpg file using gimp and push into device once again then try to run your program and check whether your image file is diplayed in your image view.

Thanks
Sunil

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文