已弃用的Canvas.getMatrix()的替代方法是什么?

时间:2012-11-03 15:01:45

标签: android android-4.2-jelly-bean

我有以下代码片段,它使用画布转换一组边界'当前转换矩阵。

    final RectF bounds = renderer.computeBounds
    activeCanvas.getMatrix().mapRect(result, bounds);
    return bounds;

但是,使用最新的API级别(16),我会收到一条警告

The method getMatrix() from the type Canvas is deprecated

API 16 Diff Specification确认。

哪个好,所有,但Canvas.getMatrix()上的当前文档没有提及弃用,也没有提供替代方案。作为一种解决方法,我现在只是简单地抑制了这个警告,但我真的想知道新的和改进的(tm)这样做是什么样的。

3 个答案:

答案 0 :(得分:9)

我认为由于issue with getMatrix when hardwareAcceleration is enabled,他们弃用了它,因为kouray说现在矩阵由视图处理。

答案 1 :(得分:8)

Matrix现在由视图而不是Canvas处理。遗憾的是,我无法解释谷歌对此问题的决定,但您应该能够通过2种方式重现完全相同的事情。

答案 2 :(得分:3)

如果您无法访问视图:

  

要解决此问题,在大多数情况下,您可以使用canvas.scale(),canvas.translate()等应用任何转换,而不是检索矩阵,修改矩阵然后再次设置矩阵。

来自Google issue with getMatrix when hardwareAcceleration is enabled,由Sandeep引用。