Skip to content

Instantly share code, notes, and snippets.

@eiszfuchs
Created October 7, 2011 11:02
Show Gist options
  • Save eiszfuchs/1270063 to your computer and use it in GitHub Desktop.
Save eiszfuchs/1270063 to your computer and use it in GitHub Desktop.
/*
import flash.display.*;
import flash.utils.*;
import mx.graphics.codec.*;
*/
var bitmap:BitmapData = new BitmapData(128, 128, true);
var x:int, y:int;
for (y = 0; y < bitmap.height; y++) {
for (x = 0; x < bitmap.width; x++) {
bitmap.setPixel32(x, y, Math.random() * 0xFFFFFFFF);
}
}
var encoder:PNGEncoder = new PNGEncoder;
var raw:ByteArray = encoder.encode(bitmap);
var file:FileReference = new FileReference();
file.save(raw, 'saveme.png');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment