Convert Gif To Png Programmatically
I have a GIF that I am grabbing from a website (http://radar.weather.gov/ridge/RadarImg/N0R/) and wanting to display to the user. I am building to Jelly Bean (4.1) and in my search
Solution 1:
After changing my question a bit, I found the answer through the almighty Google here:
http://gayashan-a.blogspot.com/2012/02/android-how-to-display-gif-image-in.html
Summarized here:
public Bitmap getBitmap(String url)
{
Bitmapbmp=null;
try
{
HttpClientclient=newDefaultHttpClient();
URIimageUri=newURI(url);
HttpGetreq=newHttpGet();
req.setURI(imageUri);
HttpResponseresp= 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;
}
This decodes it to a Bitmap which can be compressed to a PNG ...
BitmapmCurrentRadar= getBitmap("http://radar.weather.gov/ridge/RadarImg/N0R/ABC_N0R_0.gif");
ByteArrayOutputStreamstream=newByteArrayOutputStream();
mCurrentRadar.compress(Bitmap.CompressFormat.PNG, 100, stream);
... or can be immediately used in an ImageView
...
ImageViewimageView= (ImageView) findeViewById(R.id.radarImageView);
imageView.setImageBitmap(getBitmap("http://radar.weather.gov/ridge/RadarImg/N0R/ABC_N0R_0.gif");
Post a Comment for "Convert Gif To Png Programmatically"