Created
January 13, 2015 14:03
-
-
Save aaccurso/352f05e54ecc809ef482 to your computer and use it in GitHub Desktop.
Usage of canvas2ImagePlugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var saveAvatarPicture = function() { | |
| var avatar = document.createElement('canvas'), | |
| anchor; | |
| avatar.width = 470; | |
| avatar.height = this.game.height; | |
| avatar.getContext('2d').drawImage(this.game.canvas, | |
| 180, 0, | |
| avatar.width, avatar.height, | |
| 0, 0, | |
| avatar.width, avatar.height | |
| ); | |
| if (window.canvas2ImagePlugin) { | |
| window.canvas2ImagePlugin.saveImageDataToLibrary( | |
| function(msg) { | |
| console.log(msg); | |
| Dialog.alert('Guardar avatar', 'Se ha guardado tu avatar correctamente.'); | |
| }, | |
| function(err) { | |
| console.error(err); | |
| Dialog.alert('Guardar avatar', 'No se pudo guardar tu avatar.'); | |
| }, | |
| avatar | |
| ); | |
| } else { | |
| anchor = document.createElement('a'); | |
| anchor.download = 'avatar.png'; | |
| anchor.href = avatar.toDataURL('image/png'); | |
| anchor.click(); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment