Jump to content
Search Community

My ByteArray isn't retaining filters

rondog test
Moderator Tag

Recommended Posts

I have an RTMP stream that I need to take a screenshot of. I got a security error using bitmapData.draw() since it was coming from AWS S3 so I found a workaround that allows me to take a screenshot of the video:
var bitmap = new Bitmap(); 
var graphicsData : Vector.<IGraphicsData>;
graphicsData = container.graphics.readGraphicsData(); //-- container is a sprite that holds my video element 
bitmap.bitmapData = GraphicsBitmapFill(graphicsData[0]).bitmapData;
var image:ByteArray = new JPGEncoder(85).encode(bitmap.bitmapData);

At this point, I send the ByteArray to PHP, create a JPG out of the ByteArray and save it to the server. That all works great.

 
The issue is I apply filters real-time to the container sprite which alters the look of the video like brightness, contrast, saturation etc, but when saving to the server, the saved image doesn't contain the filters I had applied.
 
I tried reapplying the filters to bitmap, graphicsData and bitmap.bitmapData before sending it to the server, but nothing has worked yet.
 
How can I either retain the filters applied or re-apply the filters to the above code?
 
Here is how I initially apply the filters:
private function applyEffects(effects:Array):void
{
  currentEffects = effects;
  var props:Object = {};
  for (var i:String in effects)
  {
    props[effects[i].effect] = effects[i].amount;
  }
  TweenLite.to(container,0,{colorMatrixFilter:props});
}

props object could look something like: {contrast:0.5,saturation:1}

Link to comment
Share on other sites

Thanks for the suggestion Jack. I tried doing what you said, but it still did not work. I thought more about your suggestion and came up with a working solution!

 

var graphicsData:Vector.<IGraphicsData>;
graphicsData  = container.graphics.readGraphicsData(); 
var origBitmap:Bitmap = new Bitmap(); 
origBitmap.bitmapData = GraphicsBitmapFill(graphicsData[0]).bitmapData;


//-- at this point I have a screenshot of the video


var props:Object = {};
for (var i:String in currentEffects)
{
  props[currentEffects[i].effect] = currentEffects[i].amount;
}
TweenLite.to(origBitmap,0,{colorMatrixFilter:props});


//-- at this point I've reapplied the effects.
//-- originally, sending bitmap.bitmapData to the encoder didn't retain the filters so I went 1 step further


//-- create a new bitmapData and draw the reapplied filter'd bitmap
var filteredBitmapData:BitmapData = new BitmapData(640,360);
var filteredBitmap:Bitmap = new Bitmap(filteredBitmapData);
filteredBitmapData.draw(origBitmap);


//-- encode the new bitmap data
var image:ByteArray = new JPGEncoder(85).encode(filteredBitmapData); //-- filteredBitmapData is now filtered and I can send this to the server
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...