Reputation: 217
Am trying to set wallaper in the backround with glide.It all works fine but the applied wallaper is of like the corners of the image.Since am ruuning it in job Service i cannot use a image view to scale the image.Is there any way to crop the image without it.Triied using centerCrop() on Glide but not working.
@Override
public void onComplete(Photo photo) {
String photoUrl = photo.getUrls().getRegular();
Glide.with(getApplicationContext()).asBitmap().load(photoUrl)
.apply(new RequestOptions().centerCrop()).into(new
SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource,
@Nullable Transition<? super Bitmap> transition) {
WallpaperManager wallManager =
WallpaperManager.getInstance(getApplicationContext());
try {
wallManager.clear();
wallManager.setBitmap(resource);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Upvotes: 2
Views: 2034
Reputation: 51
You can use custom transformations to crop the bitmap at the callback method of BitmapTransformation.
And there are some very good references for transformation examples, it's very easy to use.
Here is my test code with kotlin:
val photoUrl = "imageurl"
val target = object : SimpleTarget<Bitmap>(450, 450) {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
imageView.setImageBitmap(resource)
}
}
GlideApp.with(this@MainActivity).asBitmap().load(photoUrl)
.apply(bitmapTransform(RoundedCornersTransformation(38, 0, RoundedCornersTransformation.CornerType.ALL)))
.into(target)
Upvotes: 1