iOS-deve与Starling框架:拍摄一张屏幕截图,并将其保存到相机卷中
我使用flash进行ios开发,我使用starling框架。iOS-deve与Starling框架:拍摄一张屏幕截图,并将其保存到相机卷中,ios,flash,air,starling-framework,Ios,Flash,Air,Starling Framework,我使用flash进行ios开发,我使用starling框架。 我正在尝试拍摄一个屏幕截图,然后将其保存到相机卷中,但cameraRoll只接受位图数据。如何将sprite转换为位图数据?万分感谢 您可以使用方法将Sprite转换为BitmapData。 这就是一个例子。事实上,你不能用draw来画椋鸟的精灵。 Try to get an byte array for this use can use Encoder like JPGEncoder or PNGEncoder from byte
我正在尝试拍摄一个屏幕截图,然后将其保存到相机卷中,但cameraRoll只接受位图数据。如何将sprite转换为位图数据?万分感谢 您可以使用方法将
Sprite
转换为BitmapData
。
这就是一个例子。事实上,你不能用draw来画椋鸟的精灵。
Try to get an byte array for this use can use Encoder like JPGEncoder or PNGEncoder from byte array you can easily convert to bitmapData.
And the code which i used for converting byte array to bitmapData is here. I hope it would be helpfull for you.If you send any byteArray by calling this class it would convert you bitmapData and return back using callBack Function.
package browsingImages
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.events.Event;
import flash.utils.ByteArray;
import scenes.Subscenes.KeepDiary;
public class BitmapDataConverter
{
// private var _KeepDiary:KeepDiary;
private var bmpData:BitmapData;
private var _loader:Loader;
private var _callB:Function;
public function BitmapDataConverter(byteArr:ByteArray,callB:Function)
{
_callB=callB;
getBitmapFunc(byteArr);
}
private function getBitmapFunc(bytArr:ByteArray):void{
if(bytArr != null){
bmpData = new BitmapData(100, 100, true,0xFFFFFF);
_loader = new Loader();
_loader.loadBytes(bytArr);
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderAdded);
}
}
private function onLoaderAdded(eve:Event):void{
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoaderAdded);
bmpData.draw(_loader);
bmpData = Bitmap(_loader.content).bitmapData;
if(_callB != null)
_callB(bmpData);
}
}
}
此代码适用于我:
public static function copyAsBitmapData(displayObject:DisplayObject, transparentBackground:Boolean = true, backgroundColor:uint = 0xcccccc):BitmapData
{
if (displayObject == null || isNaN(displayObject.width)|| isNaN(displayObject.height))
return null;
var resultRect:Rectangle = new Rectangle();
displayObject.getBounds(displayObject, resultRect);
var result:BitmapData = new BitmapData(displayObject.width, displayObject.height, transparentBackground, backgroundColor);
var context:Context3D = Starling.context;
var support:RenderSupport = new RenderSupport();
RenderSupport.clear();
support.setOrthographicProjection(0, 0, Starling.current.stage.stageWidth, Starling.current.stage.stageHeight);
support.applyBlendMode(true);
support.translateMatrix( -resultRect.x, -resultRect.y);
support.pushMatrix();
support.blendMode = displayObject.blendMode;
displayObject.render(support, 1.0);
support.popMatrix();
support.finishQuadBatch();
context.drawToBitmapData(result);
return result;
}