Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderstanding Android's Canvas.saveLayer(...)
    primarykey
    data
    text
    <p>I am hoping the saveLayer methods will allow me to do draw onto different "layers" and then once the drawing has finished, merge the layers with the canvas in whichever order i choose.</p> <p>The obvious question is "why dont you just rearrange your drawing operations instead?" The answer is I can't:</p> <p>I have a Path that I need to draw onto a Canvas. In the background/lowest z-index I want to draw the path closed and with a few additional points using a fill style. Then on top of that, I want to draw an outline of only the points that were originally in the Path.</p> <p>Since I cannot undo the adding of points to the Path, my only choices are to clone the path, or to draw to a second layer which can later be placed on top of everything else.</p> <p>saveLayer() seems to offer that functionality but it doesnt behave the way I was expecting. The basic flow of my operations is like this:</p> <pre><code>int overlay = canvas.saveLayer(...); // drawing operations for my uppermost layer ... int background = canvas.saveLayer(...); // drawing operations for my background layer ... // merge the offscreen background bitmap with the canvas: canvas.restoreToCount(background); // merge the offscreen overlay bitmap with the canvas: canvas.restoreToCount(overlay); </code></pre> <p>When the code runs, the ordering of background and overlay have not changed at all; what gets drawn first is at the bottom and what gets drawn last is on top. Even stranger to me is that I can completely comment out both calls to restoreToCount() and nothing changes. According to the javadoc, nothing should be drawn to the canvas until a balancing restore() is invoked.</p> <p>Obviously I am completely misunderstanding the function of this method. Can anybody help me to understand saveLayer's usage, or perhaps suggest an alternate way to layer my drawing operations?</p> <p>Thx! Nick</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.
 

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