0
votes
var dt : Date = new Date();
var jpg:JPEGEncoder= new JPEGEncoder;
var ba:ByteArray = jpg.encode(parentDocument.newBitmapData);    
file.save(ba,'Screenshot at'+dt.time+'.jpg');

I have to save the image in different sizes

for eg : 800x600, 640x480 etc

1

1 Answers

2
votes

You can just scale the bitmapData before encoding:

    var bd800x600:BitmapData = new BitmapData(800, 600);
    bd800x600.perlinNoise(10, 10, 8, 21, true, true);

    var newW:int = 640;
    var newH:int = 480;

    var bd640x480:BitmapData = new BitmapData(newW, newH);
    var mt:Matrix = new Matrix();
    mt.scale(newW/bd800x600.width, newH/bd800x600.height);
    bd640x480.draw(bd800x600, mt);

and than use your code to save the scaled bitmapdata.