我有從一個url加載一個png文件到一個ByteArrayOutputStream的代碼。現在我想將它製作成位圖,以便繪製它。我試過 位圖bBack = BitmapFactory.decodeStream(輸出);;但是,BitMapFactory不會接收yteArrayOutputStream。試圖從一個ByteArrayOutputStream創建一個位圖
我怎樣才能創造從一個ByteArrayOutputStream對象的位圖? 代碼
try {
URL url = new URL("http://stage.master.embryooptions.healthbanks.com/siteassets/24/ShadyGrove-logo.png");
InputStream is = (InputStream) url.getContent();
byte[] buffer = new byte[8192];
int bytesRead;
ByteArrayOutputStream output = new ByteArrayOutputStream();
while ((bytesRead = is.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
/////////////////////////////////////////////////////////////////////////////
// HOW DO I GET A BITMAP?????????
///////////////////////////////////////////////////////////////////////////////
// Bitmap bBack=BitmapFactory.decodeStream(output);
return "";
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
+1更好的替代方案 – Devrim