BitmapFactory.decodeStream读取Asset文件出现decoder->decode returned false错误

来源:互联网 发布:房地产大数据分析 编辑:程序博客网 时间:2024/05/22 15:26
BitmapFactory.decodeStream(InputStream is)从Asset文件中读取图像文件时,会出现decoder->decode returned false错误,可能的问题之一是读取的文件类型为jpg格式的,将图片格式转码为gif格式即解决问题。
附1:读取Asset文件(以图像文件为例)的代码:
AssetManager am = ct.getResources().getAssets();//ct为Android的Activity传入到本class的应用程序的Context
String[] files_list= am.list("trained"); //将Asset文件夹内的"trained"文件夹内的所有的文加名列到files_list内
InputStream IS = am.open("trained/" + "file_name.gif"); //将Asset/trained文件夹内部的file_name.gif文件打开成InputStream 。
Bitmap bm = BitmapFactory.decodeStream(IS);
附2:读取网络文件到Bitmap
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(getMethod, new BasicHttpContext());
HttpEntity entity = response.getEntity();
InputStream is= entity.getContent(); 
Bitmap bm = BitmapFactory.decodeStream(is);
附3:其他解决decoder->decode returned false错误的链接
http://www.newsmth.net/nForum/#!article/MobileDev/38356
http://stackoverflow.com/questions/3802820/bitmapfactory-decodestream-always-returns-null-and-skia-decoder-shows-decode-ret
http://stackoverflow.com/questions/4339082/android-decoder-decode-returned-false-for-bitmap-download
http://stackoverflow.com/questions/11047224/unable-to-load-jpeg-image-with-bitmapfactory-decodefile-returns-null
http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html
1 0
原创粉丝点击