Before you call save() on the canvas, your canvas is in a certain
state (clip region/transformation matrix/etc).
Then you call save() and all this info is saved away somewhere.

Then other code (e.g. paints of child-views) can modify this canvas
anyway they like.

Then when control is returned back to your code, just call restore
(level) on the canvas to get your old saved state back.

  // do some drawing/clipping/scaling/etc on my canvas
  ...
  ...
  int level = canvas.save();
  letSomeOtherCodeDoSomeDrawing(canvas);
  // after this, the canvas could be in any (unknown) state

  // restore to my known state, as it was just before
  // calling letSomeOtherCodeDoSomeDrawing
  canvas.restoreToCount(level);

  // do some more drawing/clipping/scaling etc on the canvas
  ...


On Aug 14, 10:55 am, Jiri <[email protected]> wrote:
> Thanks Jeff,
>
> not sure if i understand it correctly. I come from an AS3 background and
>    tf matrixes i understand.
> So if i would scale the canvas via a matrix and then draw stuff on it,
> this stuff is then scaled when drawn.
> if i then after the scaling do a restore() all is 100% scaled again?
>
> Or is that the matrix is resetted but the drawn stuff remains how it was
> before calling the restore()?
>
> jiri
>
>
>
> Jeff Sharkey wrote:
> > Think of it as checkpointing the transformation matrix and clip
> > rectangle of your Canvas at a known place in time.  This is useful
> > when rendering children views that may leave them in an unknown state.
> >  (You can restore back to the checkpointed state when children are
> > done drawing.)  Here's an example from ViewGroup:
>
> > final int restoreTo = canvas.save();
>
> > [perform some drawing that might change the transformation matrix or
> > clip rectangle]
>
> > canvas.restoreToCount(restoreTo);
>
> > j
>
> > On Thu, Aug 13, 2009 at 3:04 AM, Jiri<[email protected]> wrote:
> >> Could someone explain to me the canvas.save() and restore(). I come from
> >> a flash background, and this is a new concept for me. Reading the
> >> documentation is not helpfull.
>
> >> Jiri- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to