Skip to main content
Legend
February 27, 2013
Answered

StageWebView.drawViewPortToBitmapdata is resizing. :(

  • February 27, 2013
  • 1 reply
  • 626 views

Hi,

I've built a stage web view component that draws and maintains stage webview. For animations etc. I transpose into a bitmap.

This works fine in theory, but on my Nexus7, I am finding that the whole thing displays about fifty percent too big!

EG: Using the code below, I get traces like this:

BUILT WITH (x=0, y=60, w=1280, h=643)

/// Stuff in the middle as animation proceeds

SCALES: (x=0, y=0, w=1280, h=703)

          (x=0, y=60, w=1920, h=964.5)

As you can see, the bitmap data is created at the correct dimensions, but as soon as I display it, it seems to resize from 1280x643 to 1920x964.5...

This, I hasten to add, looks naff.

Has anybody else encountered this and has anybody else got a workaround?

Thanks,

G

/**

* When true, replaces StageWebView with an overlaid bitmap instead

* so as to ensure that animations work smoothly.

*/

[Bindable]

public function get showBitmapNotBrowser():Boolean {

          return _showBitmapNotBrowser;

}

private var _showBitmapNotBrowser:Boolean = false;

private var _showBitmapNotBrowserInvalid:Boolean = false;

public function set showBitmapNotBrowser(b:Boolean):void {

          _showBitmapNotBrowser = b;

          _showBitmapNotBrowserInvalid = true;

          invalidateProperties();

}

protected var browserBitmap:Bitmap;

override protected function commitProperties():void {

          if(_showBitmapNotBrowserInvalid) {

                    if(showBitmapNotBrowser) checkBuildBitmap();

                    else checkUnbuildBitmap();

          }

          super.commitProperties();

}

/**

* Replaces displayed browser with bitmap.

*/

protected function checkBuildBitmap():void {

          if(browserBitmap) return;

          var r:Rectangle = stageWebView.viewPort;

          trace("BUILT WITH "+r);

          var bdd:BitmapData = new BitmapData(r.width,r.height);

          stageWebView.drawViewPortToBitmapData(bdd);

          browserBitmap = new Bitmap(bdd);

          addChild(browserBitmap);

          hideStageWebView();

}

/**

* Removes a displayed browser bitmap, if any.

*/

protected function checkUnbuildBitmap():void {

          if(browserBitmap) {

                    var r:Rectangle = browserBitmap.getBounds(stage);

                    trace("SCALES: "+(new Rectangle(0,0,stage.stageWidth,stage.stageHeight))+"\n\t"+r);

                    removeChild(browserBitmap);

                    browserBitmap.bitmapData.dispose();

                    browserBitmap = null;

          }

          this.checkBrowserVisibility();

}

This topic has been closed for replies.
Correct answer Gaius Coffey

OK, I have a workaround:



/**


* Replaces displayed browser with bitmap.


*/


protected function checkBuildBitmap():void {



if(browserBitmap) return;



var r:Rectangle = stageWebView.viewPort;



var bdd:BitmapData = new BitmapData(r.width,r.height);



stageWebView.drawViewPortToBitmapData(bdd);



browserBitmap = new Bitmap(bdd);



browserBitmap.width = unscaledWidth;



browserBitmap.height = unscaledHeight;



addChild(browserBitmap);



hideStageWebView();


}

No, I know it _shoudn't_ be necessary, but it is relatively painless and it works.

G

1 reply

Gaius CoffeyAuthorCorrect answer
Legend
February 27, 2013

OK, I have a workaround:



/**


* Replaces displayed browser with bitmap.


*/


protected function checkBuildBitmap():void {



if(browserBitmap) return;



var r:Rectangle = stageWebView.viewPort;



var bdd:BitmapData = new BitmapData(r.width,r.height);



stageWebView.drawViewPortToBitmapData(bdd);



browserBitmap = new Bitmap(bdd);



browserBitmap.width = unscaledWidth;



browserBitmap.height = unscaledHeight;



addChild(browserBitmap);



hideStageWebView();


}

No, I know it _shoudn't_ be necessary, but it is relatively painless and it works.

G