Skip to content

Instantly share code, notes, and snippets.

@alijaya
Forked from anonymous/slicingbitmap
Last active December 18, 2015 21:09
Show Gist options
  • Save alijaya/5845138 to your computer and use it in GitHub Desktop.
Save alijaya/5845138 to your computer and use it in GitHub Desktop.
var bd = Assets.getBitmapData("img/sumachan.png");
var temp:BitmapData = new BitmapData(300, 300, true, 0);
temp.copyPixels(bd, new Rectangle(0, 0, 300, 300), new Point(0, 0));
var data:Data = Tools.build32ARGB(temp.width, temp.height, Bytes.ofData(temp.getPixels(temp.rect)));
var bo:BytesOutput = new BytesOutput();
var writer:Writer = new Writer(bo);
writer.write(data);
var byteArray:ByteArray = bo.getBytes().getData();
#if flash
var file:flash.net.FileReference = new flash.net.FileReference();
file.save(byteArray, "test.png");
#elseif cpp
var file:FileOutput = File.write("test.png", true);
file.writeBytes(bo.getBytes());
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment