gpt4 book ai didi

android - 在没有 ImageView 的情况下滑动裁剪图像

转载 作者:行者123 更新时间:2023-11-29 23:25:37 25 4
gpt4 key购买 nike

我正在尝试使用 glide 在后台设置 wallaper。一切正常,但应用的 wallaper 就像图像的角一样。由于在工作服务中运行它,我无法使用 ImageView 来缩放图像。是没有它,有任何方法可以裁剪图像。尝试在 Glide 上使用 centerCrop() 但不起作用。

@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();
}
}
}
}

最佳答案

您可以使用 custom transformationsBitmapTransformation 的回调方法中裁剪位图.

transformation examples 有一些很好的引用资料, 它非常易于使用。

这是我使用 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)

关于android - 在没有 ImageView 的情况下滑动裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53627526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com