开发者

Full Flex Display Object to Image

I have a requirement for generating a UIComponent displayed into an Image. Am using the PNGEncoder as well as JPEGEncoder to generate the image.

var bd:BitmapData = new BitmapData(uiComp.measuredWidth,ui开发者_如何转开发Comp.measuredHeight);
bd.draw(uiComp, new Matrix()); 
var bitmap:Bitmap = new Bitmap(bd); 
bytes = jpgenc.encode(bd);  

The code is working perfectly in normaly scenarios. But the problem comes in low resolution screens, if the canvas is having scroll bar, only the displayed contents, i mean omitting the contents belows the scrolled location is coming. Is there any way that I can convert the complete canvas completely into an image, even if it having scroll bar! Please help!

Cheers, PK


I think ImageSnapshot can take a screenshot even if the component is cut off or even if its visible property is set to false.

import mx.core.IUIComponent;
import mx.graphics.ImageSnapshot;

private function takeSnapshot(source:IBitmapDrawable):void {
    var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(source);
    var imageByteArray:ByteArray = imageSnap.data as ByteArray;
    swfLoader.load(imageByteArray);
}


Using Imagesnap with PNGEncoder i was able to get the Screenshot with compression

import flash.filesystem.FileStream;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import mx.graphics.ImageSnapshot;
import mx.graphics.codec.PNGEncoder;

... ... ... ...

ImageSnapshot.defaultEncoder = PNGEncoder;
var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(FlexGlobals.topLevelApplication as IBitmapDrawable);
var stream:FileStream = openStream("screenshot.png");
stream.writeBytes(imageSnap.data);
stream.close();

... ... ... ...

private static function openStream(fileName:String):FileStream
    {
        var file:File = File.documentsDirectory.resolvePath(fileName);
        var stream:FileStream = new FileStream();
        stream.open(file, FileMode.WRITE);
        return stream;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜