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

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错误的链接
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章