2012-05-09 6 views
0

ios開発用にFlashを使用しています。私はstarlingフレームワークを使用しています。 私はスクリーンショットを撮ってカメラロールに保存しようとしていますが、cameraRollはビットマップデータのみを受け入れます。スプライトをビットマップデータに変換する方法を教えてください。感謝万円!!iOS devel Starlingフレームワーク:スクリーンショットを撮ってカメラロールに保存します

答えて

0

Spriteにに変換することができます。BitmapData.draw()メソッドを使用してください。 Hereさんの例です。

0
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); 
     } 

    } 
} 
0

実際には、starlingのSpriteにはdrawを使用できません。 このコードは私のために動作します:

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; 
} 
関連する問題