gpt4 book ai didi

java - Glide : load specified region of image

转载 作者:太空狗 更新时间:2023-10-29 16:29:12 24 4
gpt4 key购买 nike

我使用以下代码使用 Glide 从服务器加载图像:

private void loadImage(Context context, String url, ImageView imageView, int x1, int y1, int x2, int y2) {
Glide.with(context)
.load(url)
.into(imageView);
}

我只需要在我的 ImageView 中显示一张图片。这件作品的坐标放置在变量 x1、x2、y1 和 y2 中。如何使用 Glide 只剪切需要的部分图像?

最佳答案

据我所知,glide 中没有这样的 API。但您可以手动执行此操作:

private void loadImage(Context context, String url, ImageView imageView, int x1, int y1, int x2, int y2) {
Glide.with(context)
.load(url)
.asBitmap()
.into(new SimpleTarget<Bitmap>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
Bitmap cropeedBitmap = Bitmap.createBitmap(resource, x1, y1, x2, y2);
imageView.setImageBitmap(cropeedBitmap);
}
});
}

注意,主线程正在执行一个比较重的Bitmap.createBitmap()操作。如果这会影响整体性能,您应该考虑在后台线程中执行此操作。

关于java - Glide : load specified region of image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43475496/

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