Comunidad de diseño web y desarrollo en internet online

BitmapData

Citar            
MensajeEscrito el 25 Sep 2007 07:27 pm
Hola a todos, tengo dos dudas sobre esta clase: BitmapData.

-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

Por shn

29 de clabLevel



Genero:Femenino  

firefox
Citar            
MensajeEscrito el 30 Sep 2007 10:47 pm
La velocidad para copiar la pantalla pixel a pixel es la que es en AS2.
Aunque afinando un poco el código que propones aunmentará algo la velo)
En AS3 se puede hacer muchísimo más rápido. (unas 6 veces más rápido por mis pruebas).
En cuanto a copiar pantalla.......
Creas un bitmap , un MC vacio y le draw al bitmap un _root u otro bitmap o MC que desees y un copyPixels con el rectángulo que quieras coger como parámetro.
Siendo captura el bitmap creado :

captura.draw(_root);
captura.copyPixels(captura,new Rectangle(x,y,w,h),new Point());

Luego atachas la captura (el bmp) al MC vacio e imprimes el MC

Por Teseo

SWAT Team

1780 de clabLevel

14 tutoriales

Genero:Masculino   SWAT

firefox
Citar            
MensajeEscrito el 11 Nov 2009 01:49 pm
Holas resulta que realice un flash para realizar tacticas y estrategias para juegos de futbol... ALGO MUY BASICO DE MOMENTO
mas vale una imagen que mil palabras: http://alexis-cs.freehostia.com/

Lo que intento conseguir es un funcion que permita realizar una captura de pantalla, como aqui el amigo y que pueda guardarla como una imagen...

vi lo del codigo bitmap o bitmapData. el problema es que estoy muy verde es lo de flash y scripts...

gracias...

Por Alexis-CS

7 de clabLevel



 

msie8
Citar            
MensajeEscrito el 11 Nov 2009 03:40 pm
encontre un manual perfecto para mi.. vamos como si lo hubiesen redactado para mi caso... el problema es que es MUY AVANZADO para mi...

el manual es este:
http://www.tutoriales-flash.com/tutorial.asp?id_tuto=39

alguien me ayuda..

Por Alexis-CS

7 de clabLevel



 

msie8

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.