bug56
bug56

Reputation: 154

AS3 Rasterizing Movie Clip into Sprite for Printing

I'm currently having a frustrating issue printing a multi-page document. Essentially I have one movieclip on the stage (printArea) that contains several elements including an image loaded using the loader component, a datagrid component, and some other assorted elements.

This movie clip acts as a template for a single page; you adjust options, then click "add page" and change it again for the second page and so on. The issue I'm having is with adding the page to an array to be looped through later using addPage(). As far as I understand, a sprite or movie clip would be best to pass to addPage. I feel that it's total overkill to duplicate the movie clip, then reinitialize all components with data, sizing, and positioning set. I can't pass the movieclip itself since I need several pages modeled from one instance. Is there a way to simply rasterize a movie clip to pass it to addPage()? This is the only solution I've currently found, but the quality of the printout is miserable:

//So let's say I want to add the movie clip's current state to the array :

multiPages.push(duplicateMC(printArea));
function duplicateMC(mc)
{
    var tempImg:BitmapData = new BitmapData(mc.width,mc.height);
    tempImg.draw(mc);
    var fullImg = new Bitmap(tempImg);
    var newImg = DisplayConverter.bitmapToSprite(fullImg,true);
    multiPages.push(newImg);
}

//DisplayConverter function in a seperate file (Snagged this online somewhere) :

public static function bitmapToSprite(bitmap:Bitmap, smoothing:Boolean = false):Sprite
{
    var sprite:Sprite = new Sprite();
    sprite.addChild( new Bitmap(bitmap.bitmapData.clone(), "auto", smoothing));
    return sprite;
}

Thanks in advance, this has been a huge pain for me all day.

Upvotes: 1

Views: 581

Answers (1)

The_asMan
The_asMan

Reputation: 6402

Dont over complicate it.
You are not scaling so don't turn on snapping or smoothing as this will distort the image and reduce quality.
Store the "image/BMD" in your array to refer back to it at printing time. Storing more then the BMD is wasted memory.

function doMyPrinting( ):void{
  for each( var item:BitmapData in multiPages){
    var page:Sprite = new Sprite();
    page.addChild(new Bitmap(item));
    printJob.addPage(page);
  }
}





multiPages.push(duplicateMC(printArea));
function duplicateMC(mc):void
{
    var tempImg:BitmapData = new BitmapData(mc.width,mc.height);
    tempImg.draw(mc);
    multiPages.push(tempImg);
}

Upvotes: 1

Related Questions