Reputation: 381
I am trying to set gif wallpaper but the app crashes. This works fine with simple images(png, jpg)
Error message:
java.lang.ClassCastException: com.bumptech.glide.load.resource.gif.GifDrawable cannot be cast to 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();
}
I want to set gif wallpaper(Live wallpaper)
Upvotes: 1
Views: 804
Reputation: 37404
GifDrawable
is a child of Drawable
which is returned by getDrawable()
, previously loaded using,
Glide.with(this).load(getIntent().getStringExtra("images")).into(imageView);
so GifDrawable
and BitmapDrawable
are siblings so cannot be casted to each other.
Alternatively, you can use getFirstFrame()
to get the Bitmap
as
Bitmap bitmap = ((GifDrawable)imageView.getDrawable()).getFirstFrame();
Upvotes: 2