改变我的问题有点后,我发现通过全能的谷歌这里的答案:这里总结
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