加载gif图片第一帧

public static Bitmap loadGifFirstBitmap(String url) {
        Bitmap bitmap = null;
        try {
            HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection();
            InputStream is = urlConnection.getInputStream();
            Movie movie = Movie.decodeStream(is);
            //Bitmap.Config.ARGB_8888 这里是核心,如果出现图片显示不正确,就换编码试试
            bitmap = Bitmap.createBitmap(movie.width(), movie.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            movie.draw(canvas, 0, 0);
            canvas.save();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            return bitmap;
        }
    }


 
   

你可能感兴趣的:(andorid)