簡體   English   中英

無法使用滑行加載 gif 圖像

[英]Failed to load gif images with glide

我正在嘗試設置 gif 壁紙,但應用程序崩潰了。 這適用於簡單的圖像(png,jpg)

錯誤信息:

java.lang.ClassCastException: com.bumptech.glide.load.resource.gif.GifDrawable 不能轉換為 android.graphics.drawable.BitmapDrawable

Glide.with(this).load(getIntent().getStringExtra("images")).into(imageView);

Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
        WallpaperManager manager =  WallpaperManager.getInstance(getApplicationContext());
        try {
            manager.setBitmap(bitmap);
            Toasty.success(getApplicationContext(), "Set Wallpaper Successfully", Toast.LENGTH_SHORT, true).show();

        }
        catch (IOException e) {
            Toasty.warning(this, "Wallpaper not load yet!", Toast.LENGTH_SHORT, true).show();
        }

我想設置gif壁紙(動態壁紙)

GifDrawableDrawable的子級,它由getDrawable()返回,之前使用加載,

Glide.with(this).load(getIntent().getStringExtra("images")).into(imageView);

所以GifDrawableBitmapDrawable是兄弟,所以不能相互轉換。

或者,您可以使用getFirstFrame()Bitmap作為

 Bitmap bitmap = ((GifDrawable)imageView.getDrawable()).getFirstFrame();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM