1

我正在 Adob​​e AIR 中为 iOS 开发游戏,我想截取屏幕截图(或屏幕特定部分/电影剪辑的位图捕获)。我已经读过可以使用本机扩展来截取屏幕截图,但我实际上并不需要整个屏幕,我只需要 Adob​​e AIR 中特定影片剪辑(或屏幕区域,如果可能的话)的位图表示。我认为我不需要访问本机 SDK 来实现这一点,但我找不到任何资源来实现我想要做的事情。

如何在使用本机扩展的情况下在 Adob​​e AIR 中保存影片剪辑的“位图快照”?

谢谢,

能。

4

1 回答 1

1

如果您只需要空中应用程序中的内容快照(例如 MovieClip/其他 DisplayObject),您可以使用 BitmapData 的draw()方法:

/*
* getSnapshot - simple snapshot of a DisplayObject
* @param matrix - the transformation matrix of the object to be drawn(translation/rotation/scale)
*                 use this parameter to include the object's tranformations or an arbitrary one. 
*                 Ex. getSnapshot(myClip,myClip.transform.concatenatedMatrix);
* @param coordinateSpace - the coordinate space from used to get bounds. if you're object's rotated, 
*                          the by passing null, the bitmap will include all contents, otherwise it will be
*                          clipped using the original/'unrotated' bounds.
*/
function getSnapshot(obj:DisplayObject,matrix:Matrix = null,coordinateSpace:DisplayObject = null):BitmapData{
    var bounds:Rectangle = obj.getBounds(coordinateSpace);
    var result:BitmapData = new BitmapData(bounds.width,bounds.height,true,0x00FFFFFF);
    result.draw(obj,matrix);
    return result;
}

例如

var test:Shape = addChild(new Shape()) as Shape;
test.graphics.beginFill(0);test.graphics.drawRect(0,0,100,100);test.graphics.endFill();

var snapShot:Bitmap = addChild(new Bitmap(getSnapshot(test))) as Bitmap;
snapShot.x = test.width+10;

function getSnapshot(obj:DisplayObject,matrix:Matrix = null,coordinateSpace:DisplayObject = null):BitmapData{
    var bounds:Rectangle = obj.getBounds(coordinateSpace);
    var result:BitmapData = new BitmapData(bounds.width,bounds.height,true,0x00FFFFFF);
    result.draw(obj,matrix);
    return result;
}
于 2013-02-23T14:48:54.763 回答