改變我的問題有點後,我發現通過全能的谷歌這裏的答案:這裏總結
http://gayashan-a.blogspot.com/2012/02/android-how-to-display-gif-image-in.html
:
public Bitmap getBitmap(String url)
{
Bitmap bmp = null;
try
{
HttpClient client = new DefaultHttpClient();
URI imageUri = new URI(url);
HttpGet req = new HttpGet();
req.setURI(imageUri);
HttpResponse resp = client.execute(req);
bmp = BitmapFactory.decodeStream(resp.getEntity().getContent());
}
catch(URISyntaxException ex)
{
Log.e("ERROR", ex.getMessage());
}
catch(ClientProtocolException ex)
{
Log.e("ERROR", ex.getMessage());
}
catch(IllegalStateException ex)
{
Log.e("ERROR", ex.getMessage());
}
catch(IOException ex)
{
Log.e("ERROR", ex.getMessage());
}
return bmp;
}
這是解碼爲可被壓縮的位圖到PNG ...
Bitmap mCurrentRadar = getBitmap("http://radar.weather.gov/ridge/RadarImg/N0R/ABC_N0R_0.gif");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mCurrentRadar.compress(Bitmap.CompressFormat.PNG, 100, stream);
...或者可以是imm在ImageView
ediately使用...
ImageView imageView = (ImageView) findeViewById(R.id.radarImageView);
imageView.setImageBitmap(getBitmap("http://radar.weather.gov/ridge/RadarImg/N0R/ABC_N0R_0.gif");
這似乎在Android 4.4的奇巧GIF失去透明性做'BitmapFactory.decodeStream時()'。所以除非我失去了一些東西,當壓縮到PNG透明度仍然失去。 [問題報告](https://code.google.com/p/android/issues/detail?id=62016)。 – paul 2013-11-12 02:18:33
你可以在代碼中指定mCurrentRadar的對象類型嗎? Thx – IcedDante 2014-02-27 13:48:38
@IcedDante mCurrentRadar必須是位圖實例的一種方法。 – Lanitka 2016-08-05 10:05:37