Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 871
Paul-Jan Avatar asked Sep 12 '25 08:09

Paul-Jan


2 Answers

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.

like image 135
ben Avatar answered Sep 14 '25 00:09

ben


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.

like image 30
Sandeep Manne Avatar answered Sep 13 '25 23:09

Sandeep Manne