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错误的链接