Add misc export: download selected frame as png

This commit is contained in:
Dávid Szabó
2016-09-23 16:35:22 +02:00
parent 7b512f6412
commit 3be2b3d3bc
2 changed files with 22 additions and 0 deletions

View File

@@ -12,6 +12,9 @@
ns.MiscExportController.prototype.init = function () {
var cDownloadButton = document.querySelector('.c-download-button');
this.addEventListener(cDownloadButton, 'click', this.onDownloadCFileClick_);
var selectedFrameDownloadButton = document.querySelector('.selected-frame-download-button');
this.addEventListener(selectedFrameDownloadButton, 'click', this.onDownloadSelectedFrameClick_);
};
ns.MiscExportController.prototype.onDownloadCFileClick_ = function (evt) {
@@ -73,4 +76,14 @@
hexStr += ('00' + r.toString(16)).substr(-2);
return hexStr;
};
ns.MiscExportController.prototype.onDownloadSelectedFrameClick_ = function (evt) {
var frameIndex = this.piskelController.getCurrentFrameIndex();
var fileName = this.getPiskelName_() + '-' + (frameIndex + 1) + '.png';
var canvas = this.piskelController.renderFrameAt(frameIndex, true);
pskl.utils.BlobUtils.canvasToBlob(canvas, function(blob) {
pskl.utils.FileUtils.downloadAsFile(blob, fileName);
});
};
})();