Created
September 6, 2015 03:15
-
-
Save jz5/022a4b17b968a8fdb2a0 to your computer and use it in GitHub Desktop.
This file contains 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
DrawingBoard.Board.prototype.downloadImg = function () { | |
var canvas = $("canvas").get(0); | |
var base64 = canvas.toDataURL(); | |
var blob = Base64toBlob(base64); | |
saveBlob(blob, "pronama-chan-tshirt.png"); | |
}; | |
function Base64toBlob(_base64) { | |
var i; | |
var tmp = _base64.split(','); | |
var data = atob(tmp[1]); | |
var mime = tmp[0].split(':')[1].split(';')[0]; | |
var arr = new Uint8Array(data.length); | |
for (i = 0; i < data.length; i++) { arr[i] = data.charCodeAt(i); } | |
var blob = new Blob([arr], { type: mime }); | |
return blob; | |
} | |
function saveBlob(_blob, _file) { | |
if ( /*@cc_on ! @*/ false) { | |
window.navigator.msSaveBlob(_blob, _file); | |
} | |
else { | |
var url = (window.URL || window.webkitURL); | |
var data = url.createObjectURL(_blob); | |
var e = document.createEvent("MouseEvents"); | |
e.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
var a = document.createElementNS("http://www.w3.org/1999/xhtml", "a"); | |
a.href = data; | |
a.download = _file; | |
a.dispatchEvent(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment