gpt4 book ai didi

android - 用 `canvas.clipRect` 替代已弃用的 `Region.Op.REPLACE` ?

转载 作者:行者123 更新时间:2023-12-04 23:50:02 26 4
gpt4 key购买 nike

我有以下代码:

 private RectF tmpRect = new RectF();

public void drawClipedBitmap(Bitmap bmp, Polygon tmpPoly, int x, int y) {
this.canvas.clipPath(getPath(tmpPoly));
this.canvas.drawBitmap(bmp, (float) x, (float) y, this.fillPaint);
this.tmpRect.set(0.0f, 0.0f, (float) this.canvas.getWidth(), (float) this.canvas.getHeight());
this.canvas.clipRect(this.tmpRect, Op.REPLACE);
}

但自 Android SDK28 以来,clipRect 的实现已被弃用并退出。
我正在尝试 4 个小时来找到一种方法来用其他方法替换该方法,但未成功。

由于 clipRect 已被弃用且不再工作,我如何获得相同的结果?

最佳答案

我自己发现:

public void drawClipedBitmap(Bitmap bmp, Polygon tmpPoly, int x, int y) {
Path p = getPath(tmpPoly);
Log.d("POINTS","POINTS: "+p);
this.canvas.clipPath(getPath(tmpPoly));
this.canvas.drawBitmap(bmp, (float) x, (float) y, this.fillPaint);
this.tmpRect.set(0.0f, 0.0f, (float) this.canvas.getWidth(), (float) this.canvas.getHeight());
//this.canvas.clipRect(this.tmpRect, Op.REPLACE);
this.canvas.save();
float fWidth = (float)this.canvas.getWidth();
float fHeight = (float)this.canvas.getHeight();
//this.canvas.drawRect(0, 0, fWidth, fHeight, new Paint());
this.canvas.clipRect(0.0f, 0.0f, fWidth, fHeight);
this.canvas.restore();
}

关于android - 用 `canvas.clipRect` 替代已弃用的 `Region.Op.REPLACE` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59270033/

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