我有以下代码:
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 已被弃用且不再可用?
this.tmpRect()
是什么,但你可能只需使用Canvas.save()/restore()
。 - greeble31