Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to rotate Path the same way as a Bitmap
    primarykey
    data
    text
    <p>I'm finding very little documentation on how Path objects are manipulated, specifically rotation.</p> <p>I have a painting app where I am trying to incorporate an "undo" feature. Every time the user's finger touches the view until their finger is lifted - the path of their finger is saved as a <a href="http://developer.android.com/reference/android/graphics/Path.html" rel="noreferrer">Path</a> in an ArrayList. The undo method is like so:</p> <pre><code> public void undo() { //If nothing was drawn, do nothing int size = path_history.size(); if (size == 0) return; //Draw the last saved bitmap setupView(); //Loop through saved paths, don't paint last path - remove it for (int i=0; i&lt;size-1; i++) canvas.drawPath(path_history.get(i), paint); path_history.remove(size-1); invalidate(); } </code></pre> <p>The problem is this does not work after the screen is rotated because I redraw the the bitmap rotated at a 90 degree angle (so as far as the user is concerned the drawing never rotates). The paths are redrawn as if the view is in the original orientation so the paths and the original bitmap are then out of sync.</p> <p>To compensate I've tried:</p> <pre><code>Matrix m = new Matrix(); m.preRotate(90); //I TRIED THIS TOO: m.preRotate(90, bitmap width / 2, bitmap height / 2); for (int i=0; i&lt;size-1; i++) path_history.get(i).transform(m); </code></pre> <p>The above rotation is so bad the paths aren't even redrawn on the screen. If I use the commented out rotation it at least appears on screen but still far off. How can I rotate the paths the same way the bitmap is rotated? I'm thinking part of the problem is I don't know around what coordinate they are rotated to begin with I have found no documentation on that.</p> <p>Thank you!</p> <p>Matt.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload