Well, here goes nothing - for the experienced among us! I've tried a lot of different things to get this working, but my main issue here is that saving a PNG file from a canvas seems to lose some of its transparency, creating a dark grey border around the image.
The loss in transparency ruins the image for its intended purpose, so I am looking for some help in figuring out how to save a snapshop of a display object without any loss in transparency.
Here's a sample image:
And here's the script:
Or use the JS file included in this post instead.
If you run the example above you will see that the result produces an exact copy when saved directly from the bitmap, but when it saves from a canvas extraction it loses transparency.
I was wondering if anyone knows of a better method to take a snapshot of a display object and all its children and changes with no loss of transparency information.
Hope someone is able to come up with some ideas!
The loss in transparency ruins the image for its intended purpose, so I am looking for some help in figuring out how to save a snapshop of a display object without any loss in transparency.
Here's a sample image:
And here's the script:
Code:
var bootSaveTest = Scene_Boot.prototype.start;
Scene_Boot.prototype.start = function() {
bootSaveTest.call(this);
var saveImage = function(imageName, canvas) {
var fs = require('fs');
var path = require('path');
var base = path.dirname(process.mainModule.filename);
var dataURL = canvas.toDataURL("image/png", 1);
var dirPath = base + '/';
// Make File Name
var fileName = dirPath + imageName + '.png';
// Get Base 64 Data
var base64Data = dataURL.replace(/^data:image/png;base64,/, "");
// Write File
fs.writeFileSync(fileName, base64Data, 'base64', function(err) { console.log(err); });
};
var bitmap = ImageManager.loadBitmap('', 'sheer', 0, 0);
bitmap.addLoadListener(function(source) {
var sprite = new Sprite(source);
var canvas1 = Graphics._renderer.extract.canvas(sprite);
sprite.setColorTone([-255, 0, 0, 0]);
var canvas2 = Graphics._renderer.extract.canvas(sprite);
saveImage('sheer_bitmap', source._canvas);
saveImage('sheer_sprite', canvas1);
saveImage('sheer_spriteColor', canvas2);
}.bind(this, bitmap))
};
If you run the example above you will see that the result produces an exact copy when saved directly from the bitmap, but when it saves from a canvas extraction it loses transparency.
I was wondering if anyone knows of a better method to take a snapshot of a display object and all its children and changes with no loss of transparency information.
Hope someone is able to come up with some ideas!
Attachments
-
1.1 KB Views: 6



