BitmapFactory.de codeFILE(字符串的ImagePath)返回null即使存在图像 [英] BitmapFactory.decodeFile(String imagePath) returns null even image exists

查看:180
本文介绍了BitmapFactory.de codeFILE(字符串的ImagePath)返回null即使存在图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道,为什么我从BitmapFactory.de codeFILE(字符串的ImagePath)方法越来越空。
的ImagePath是完美的。code低于此。

I don't know , why I am getting null from BitmapFactory.decodeFile(String imagePath) method. imagePath is perfect.Code is below here .

public static byte[] imageToByteArray(String imagePath){
        Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

        bitmap.compress(Bitmap.CompressFormat.JPEG , 100 , byteArrayOutputStream);
        return byteArrayOutputStream.toByteArray();
    }

imaagePath是网络特定的路径。在这里我使用谷歌的地方API和的ImagePath是由谷歌Web服务给定的图像的位置。

imaagePath is a internet specific path .Here I am using google place api and imagePath is location of image given by google web service.

推荐答案

<一个href=\"http://developer.android.com/reference/android/graphics/BitmapFactory.html#de$c$cFile%28java.lang.String%29\"相对=nofollow>德codeFILE 是用来获取位图从本地文件系统。

decodeFile is use to get Bitmap from local File system.

Decode a file path into a bitmap. If the specified file name is null, or cannot be decoded into a bitmap, the function returns null.

要获得位图从互联网上使用

Bitmap bitmap = BitmapFactory.decodeStream(imageUrl.openConnection().getInputStream());

不要忘了上面一行在后台线程中运行。

Do not forget to run above line in background thread.

这篇关于BitmapFactory.de codeFILE(字符串的ImagePath)返回null即使存在图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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