gpt4 book ai didi

带有 picasso 的Android圆形图像

转载 作者:搜寻专家 更新时间:2023-11-01 07:47:15 25 4
gpt4 key购买 nike

我想用 5px 圆角图像以显示在 picasso 的 imageview 上。我创建了一个简单的类作为 ImageRoundCorners,我在其中使用简单的方法来圆角图像,但是我的代码不起作用,角没有圆角。下面是我的代码:

   file = new File(APP.DIR_APP + APP.IMAGE + "/ok.jpg");
if (file.isFile() && file.exists()) {
Uri uri = Uri.fromFile(file);
Picasso.with(this).load(uri).transform(new ImageRoundCorners()).into(fiv_image_view);
}

ImageRoundCorners类:

import com.squareup.picasso.Transformation;

public class ImageRoundCorners implements Transformation {
@Override
public Bitmap transform(Bitmap source) {
Bitmap output = Bitmap.createBitmap(source.getWidth(), source
.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);

final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, source.getWidth(), source.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = 50;

paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(source, rect, rect, paint);

return output;
}

@Override
public String key() {
return "RoundImage";
}
}

这段代码有什么问题,我该如何解决?

我收到这个错误:

java.lang.IllegalStateException: Transformation RoundImage mutated input Bitmap but failed to recycle the original.

最佳答案

错误信息很清楚。您只是忘记回收原始位图。

....
canvas.drawBitmap(source, rect, rect, paint);
source.recycle();
return output;

您的代码只少了一行! (我对所有这些告诉你做各种不相关的、连根拔起的解决方案的答案感到惊讶。)

关于带有 picasso 的Android圆形图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41436999/

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