![]() ![]() The save method can be used to save the state of the drawing context, and then the restore can set it back. Using the canvas save method when this is the only change is kind of over kill, still you get the basic idea of what the canvas save and restore methods are used for. I then call the restore method and then the old fill color is restored at which point I draw another square that sure enough is red the original color that is was set to before calling save. ![]() I then change the fill style of the saved context to blue, and draw another square. I set the drawing fill style of the daring context to red and draw a square first, then call the canvas save method to save that context state. 1 - Basic canvas save method exampleįor starters with the canvas save method, in this example I am just using it to save the drawing context and then just change the fill color of the drawing context. So in this post I will be going over some quick examples of the canvas save method, and may other related context methods to point out some reasons why the method is so useful. Something can then be drawn with this new mutated 2d drawing context state, and then put back the way it was with the canvas restore method once I am done drawing to it. So the canvas save and restore methods are useful when using methods that mutate the drawing context in this way.įor example the canvas save method can be used to save the current state of the drawing context, and then changes can be made to the fill style, translations, and rotations. These kinds of methods differ from methods that are used to set properties to given arguments or just simply setting properties. The reason why is because these are methods that mutate the state of a drawing context by way of delta values that are passed as arguments. Once a context has been saved it can later be restored with the canvas restore method.īecause the canvas save method can be used to save a current state of a drawing context, it can come in handy when using other 2d context methods like canvas translate, and canvas rotate which are two that come to mind right off the bat when it comes to using the canvas save method. The canvas save 2d draw context method can be used to save the state of a 2d canvas drawing context. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |