【问题标题】:Write a specific movie clip to bitmap in Adobe AIR在 Adob​​e AIR 中将特定影片剪辑写入位图
【发布时间】:2013-02-23 14:29:38
【问题描述】:

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

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

谢谢,

可以。

【问题讨论】:

  • .swf 或 .mp4 格式的电影剪辑?
  • 在 swf 中的常规 Flash 影片剪辑对象。

标签: ios actionscript-3 air screenshot


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    • 2014-08-28
    • 2012-01-25
    相关资源
    最近更新 更多