我需要生成显示在Image中的UIComponent。我使用PNGEncoder和JPEGEncoder来生成图像。
var bd:BitmapData = new BitmapData(uiComp.measuredWidth,uiComp.measuredHeight);
bd.draw(uiComp, new Matrix());
var bitmap:Bitmap = new Bitmap(bd);
bytes = jpgenc.encode(bd);
代码在normaly场景中完美运行。但问题出现在低分辨率屏幕上,如果画布有滚动条,只显示内容,我的意思是省略滚动位置下面的内容。有没有办法可以将完整的画布完全转换为图像,即使它有滚动条!请帮忙!
干杯,PK
答案 0 :(得分:1)
我认为即使组件被切断,或者即使其visible属性设置为false,ImageSnapshot也可以截取屏幕截图。
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);
}
答案 1 :(得分:0)
使用Imagesnap和PNGEncoder我能够获得带压缩的屏幕截图
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;
}