Skip to main content
Inspiring
August 28, 2012
Question

drawToBitmapData on iOS

  • August 28, 2012
  • 1 reply
  • 1202 views

Hi guys,

I just installed the latest version of Air hoping there was some changes on this, but I still have a problem so let me try to ask your help...

I have to render the stage3d on a bitmap, like a screenshot, and to do this I’m using the drawToBitmapData function, like the example on the API documentation.

This works fine on desktop but not on mobile, for example on my iPad3, where nothing is shown.

I noticed, reading around, that if put a call to the render function every frame, then also on ipad I see correctly the render result moved on a bitmap and pasted over the stage. But not using a single call, that is what I need.

So, with a function like this:

private function render(event:Event):void {

   stage3d.context3D.clear(0, 0, 0, 1);

   stage3d.context3D.drawTriangles(quadIndices);

   stage3d.context3D.drawToBitmapData(bd);

   stage3d.context3D.present();                       

  

   var bitmap:Bitmap = new Bitmap(bd);

   addChild(bitmap);

}

on mobile I have a working result only adding a ’addEventListener(Event.ENTER_FRAME, render)’

what do you think?

thanks!

This topic has been closed for replies.

1 reply

Inspiring
August 28, 2012

I'm gonna crazy...

it's not possible on iPad to render on a bitmap without to insert the function call into a onFrame loop for some absurd reason, so you can imagine the performance...

so at some point I have to remove that listener and I thought to wait until the last pixels of the bitmapData are different from zero (because there aren't event linked to drawToBitmapData to handle and wait for)... well, another issue... on ipad the getpixel always return zero and not the value I expect (like on desktop tests)

are there some other way to get a screenshot from stage3d on a damn iOS device?

Participant
September 10, 2014

Did you get this working?

Colin Holgate
Inspiring
September 10, 2014

I wonder how expensive that method is considering the size of some frame buffers. On the iPad retina the frame buffer is very large (2048x1536 = 3MB). I wonder if passing all of those pixels back would cost you compared to only passing back a 256x256 (64KB) bitmap when that's all you need.


My assumption, hope, is that we're not talking about 60 times per second! Just a general ability to snapshot the current camera. The bitmapdata that is created isn't on the GPU, so you have the regular app memory to hold it, and if you're reusing the same bitmapdata it won't add up over time.