0

Haxeプログラミング言語では、ピクセルデータの配列をファイル(BMPまたはPNG形式など)に保存するための言語を超えた方法はありますか?

class SavePixelsToFile {
  static function main(){
    //how can I save this array of pixel data to a file? It is a simple 2D array of RGB arrays, with the red, green, and blue components in the respective order.
    var arr = [
      [[0, 0, 0],[255, 255, 255]],
      [[255, 255, 255],[0, 0, 0]]
      ];
  }
}
4

2 に答える 2

2

フォーマットライブラリはあなたが望むことをします。http://code.google.com/p/hxformat/

このライブラリをインストールします: haxelib インストール形式

-lib 形式を使用して、hxml ファイルにリンクします。

イメージ データをファイルに書き込むには、次の手順を実行します。

function writePixels24(file:String, pixels:haxe.io.Bytes, width:Int, height:Int) {
    var handle = sys.io.File.write(file, true);
    new format.png.Writer(handle)
        .write(format.png.Tools.build24(width, height, pixels));
    handle.close();
}

var bo = new haxe.io.BytesOutput();
for (pixel in pixels)
    for (channel in pixel) 
         bo.writeByte(channel);
var bytes = bo.getBytes();
writePixels24("Somefile.png", bytes);

これは、sys.* パッケージ (フラッシュではない) を持つターゲットで機能します。sys.* パッケージがなくても png を生成できますが、別の方法でファイルを保存する必要があります。

于 2012-12-26T05:31:48.413 に答える
0

書きやすい形式はPPMです。netpbm ツールはそれらを簡単に操作でき、 PBMPNGなどの多くの形式に変換することもできます。

于 2012-12-25T23:25:59.123 に答える