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