Created
August 5, 2014 11:28
-
-
Save shimomura1004/53b4a414fa4e328752e9 to your computer and use it in GitHub Desktop.
node-bitmap と node-pngjs で適当に変換するやつ(未完成)
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
var fs = require('fs'); | |
var Bitmap = require('node-bitmap'); | |
var PNG = require('pngjs').PNG; | |
var filepath = "/Users/shimo/tmp/1.bmp"; | |
var stat = fs.statSync(filepath); | |
var buf = new Buffer(stat.size); | |
var fd = fs.openSync("/Users/shimo/tmp/1.bmp", "r"); | |
fs.readSync(fd, buf, 0, stat.size); | |
var bmp = new Bitmap(buf); | |
bmp.init(); | |
var bitmapArray = bmp.getData(); | |
console.log(bitmapArray.length); | |
var png = new PNG({ width: 1280, height: 720, filterType: -1 }); | |
var dst = fs.createWriteStream('out.png'); | |
for (var y = 0; y < png.height; y++) { | |
for (var x = 0; x < png.width; x++) { | |
var idx = (png.width * y + x) << 2; | |
png.data[idx] = 0; | |
png.data[idx + 1] = 0; | |
png.data[idx + 2] = 0; | |
png.data[idx + 3] = 0xff; | |
} | |
} | |
png.pack().pipe(dst); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment