-La primera es sobre un ejemplo muy bueno que obtiene pixel por pixel y lo envia a un php para que pueda ser visto. El problema es que cuando lo subo al servidor, demora demasiado en hacer ese proceso y por lo tanto se cuelga. Yo simplemente quiero capturar lo que esta en la pantalla y enviarlo al php, sin importan mucho los colores y efectos.
Código :
import flash.display.BitmapData; import flash.filters.DropShadowFilter import flash.filters.BlurFilter; import flash.geom.Matrix; import flash.filters.ColorMatrixFilter; //Build color Matrix Filter var matrix:Array = new Array(); matrix = matrix.concat([1, 0, 0, 1, 0]); // red matrix = matrix.concat([0, 1, 0, 0, 0]); // green matrix = matrix.concat([0, 0, 1, 1, 0]); // blue matrix = matrix.concat([0, 0, 0, 1, 0]); // alpha var filterCol:ColorMatrixFilter = new ColorMatrixFilter(matrix); //procces bar not visible preloader._visible = false //Build Shadow Filter var shadowFilter:DropShadowFilter = new DropShadowFilter(5, 45, 0x000000, 100, 20, 20, 2, 2, false, false, false) //Build BlurFilter var blur:BlurFilter = new BlurFilter(10, 10, 2); //Array of filters myFilters = new Array(shadowFilter, blur, filterCol) //Buttons handlers. Should add an extra function because delegate doesn't allow to pass parameters colF.onPress = mx.utils.Delegate.create(this,makeColor); shaF.onPress = mx.utils.Delegate.create(this,makeShadow); bluF.onPress = mx.utils.Delegate.create(this,makeBlur); //Helper functions to pass parameters function makeShadow() { capture(0) } function makeBlur(){ capture(1) } function makeColor(){ capture(2) } /* create a function that takes a snapshot of the Video object whenever it is called and shows in different clips */ function capture(nr){ //snapshot = new BitmapData(output_vid._width,output_vid._height); snapshot = new BitmapData(output_vid._width,output_vid._height); //draw the current state of the Video object into //the bitmap object with no transformations applied snapshot.draw(output_vid,new Matrix()); var t:MovieClip = createEmptyMovieClip("bitmap_mc",1); t._x = 350; t._y = 20; t._xscale = t._yscale = 50 //display the specified bitmap object inside the movie clip t.attachBitmap(snapshot,1); var filterArray = new Array(myFilters[nr]) t.filters = filterArray attachMovie("print_but", "bot", 100, {_x:t._x+t._width+50, _y:t._y+t._height/2}) } //Create a new bitmapdata, resize it 50 %, pass image data to a server script // using a LoadVars object (large packet) function output(who){ //preloader visible preloader._visible = true //Here we will copy pixels data var pixels:Array = new Array() //Create a new BitmapData var snap = new BitmapData(who.width, who.height); //Matrix to scale the new image myMatrix = new Matrix(); myMatrix.scale(0.5, 0.5) //Copy video image snap.draw(who, myMatrix); //Uncoment this line if you want to apply filters instead of just capturing source // results should be adjusted based on your library version, not recomended //snap.applyFilter(snap, snap.rectangle, snap.rectangle.topLeft, myFilters[nr]) var w:Number = snap.width, tmp var h:Number = snap.height //Build pixels array using an onEnterframe to avoid timeouts, capture a row per iteration, show a progressbar var a:Number = 0 this.onEnterFrame = function(){ for(var b=0; b<=h; b++){ var alpha:String = (snap.getPixel32(a, b) >> 24 & 0xFF).toString(16); var red:String = (snap.getPixel32(a, b) >> 16 & 0xFF).toString(16); var green:String = (snap.getPixel32(a, b) >> 8 & 0xFF).toString(16); var blue:String = (snap.getPixel32(a, b) & 0xFF).toString(16); tmp = "0x" + red + green + blue; pixels.push(tmp); } perc = int((a*100)/w) preloader.perc.text = perc+" %" preloader.barra._xscale = perc a++ if(a>w){ //Finish capturing preloader._visible = false sendData(pixels, h, w) //free memory snap.dispose() delete this.onEnterFrame } } } //Capture a clip into a BitmapData object and pass whitout resizing function outputClip(who){ //preloader visible preloader._visible = true //Here we will copy pixels data var pixels:Array = new Array() //Create a new BitmapData var snap = new BitmapData(who._width, who._height); snap.draw(who); var w:Number = snap.width, tmp var h:Number = snap.height //Build pixels array using an onEnterframe to avoid timeouts, capture a row per iteration, show a progressbar var a:Number = 0 this.onEnterFrame = function(){ for(var b=0; b<=h; b++){ tmp = snap.getPixel32(a, b).toString(16) pixels.push(tmp.substr(1)) } perc = int((a*100)/w) preloader.perc.text = perc+" %" preloader.barra._xscale = perc a++ if(a>w){ //Finish capturing preloader._visible = false sendData(pixels, h, w) //free memory snap.dispose() delete this.onEnterFrame } } } function sendData(pixels:Array, h:Number, w:Number){ //Create the LoadVars object and pass data to PHP script var output:LoadVars = new LoadVars() output.img = pixels.toString() output.height = h output.width = w //The page (and this movie itself) should be in a server to work output.send("show.php", "output", "POST") } stop()
- Y mi ultima duda es sobre la impresion. Quiero capturar la pantalla (todo el swf) con las ultimas modificaciones que le puedo hacer.
Es decir supongamos que sea una rompecabezas en flash, con objetos a los que les haga drag y quisiera capturar la imagen de mis piezas ordenadas.
Como hago para imprimir eso, utilizando bitmap. Por lo que he leido tendria que utilizar el metodo draw, sin embargo como parametros deberia de colocar un movie clip, en este caso que quiero capturar toda la pantalla con los ultimos cambios, que debo colocar?
ESPERO PUEDAN AYUDARME, SE LOS AGRADEZCO DE ANTEMANO