Search code examples
iphoneactionscript-3actionscriptairadobe

Phone saves only the top left corner of the image - ActionScript3


I am trying to save an image to my phone's camera Roll using Action Script 3. The image saves fine on tablet devices. However, when I save the image to my phone, it saves only the top-left corner of the image.

Here is my code,

var media:DisplayItem;

public function SaveAsBitmap():void
{
var cameraRoll:CameraRoll = new CameraRoll();
cameraRoll.addBitmapData(this.GetAsBitmapData());
}

public function GetAsBitmapData():BitmapData
{
var bmpData:BitmapData = new BitmapData(this.width,this.height, false, 0x000000);
this.media.DrawToBitmap(bmpData);     
return bmpData;       
}

How do I save an image which is larger than the display area of my phone? Any help appreciated.


Solution

  • In this line:

      var bmpData:BitmapData = new BitmapData(this.width,this.height, false, 0x000000);
    

    Check the value of these variables: 'this.width' and 'this.height', probably it's not the right dimensions as you want.

    To check the user screen resolution, you can try:

      // remember to import 
      import flash.system.Capabilities;
    
      trace('Capabilities.screenResolutionX: ', Capabilities.screenResolutionX);
      trace('Capabilities.screenResolutionY: ', Capabilities.screenResolutionY);
    

    I also saw something on your code, I cannot see all scope, but try to do something:

      public function GetAsBitmapData():BitmapData
      {
         // you can replace this.width and this.height to Capabilities.screenResolutionX/Capabilities.screenResolutionY
         var bmpData:BitmapData = new BitmapData(this.width,this.height, false, 0x000000);
         bmpData.draw(this.media); // be sure that this.media is IBitmapDrawable
         return bmpData;      
      }