Paul-Jan
Paul-Jan

Reputation: 17278

What is the alternative for deprecated Canvas.getMatrix()?

I have the following code snippet, that transforms a set of bounds using the canvas' current transformation matrix.

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

However, with the latest API level (16) I get a warning stating

The method getMatrix() from the type Canvas is deprecated

as confirmed by the API 16 Diff Specification.

Which is fine and all, but the current documentation on Canvas.getMatrix() doesn't mention the deprecation, nor does it offer an alternative. As a workaround I now simply suppress this warning, but I would really like to know what the new and improved (tm) way of doing this looks like.

Upvotes: 25

Views: 9121

Answers (3)

Lucy
Lucy

Reputation: 684

If you don't have access to a view:

To work around the problem, in most situations, you can apply any transformations using canvas.scale(), canvas.translate(), etc. rather than retrieving the matrix, modifying it and then setting the matrix again.

From the Google issue with getMatrix when hardwareAcceleration is enabled, as referenced by Sandeep.

Upvotes: 4

Sandeep Manne
Sandeep Manne

Reputation: 6092

I think because of the issue with getMatrix when hardwareAcceleration is enabled, they deprecated it, as kouray said now matrix is handled by the view.

Upvotes: 9

ben
ben

Reputation: 1161

The Matrix is now handled by the view rather than the Canvas. I unfortunately can't explain you Google's decision on this one, but you should be able to reproduce the exact same things with the 2 ways.

Upvotes: 9

Related Questions