Tengo en una web un grafico (charts) generado por flash que lee a travez de un xml, que se genera con php.
Logre pasar el swf a un jpg simulando un printScreen
Archivo Flash
Código :
function print_me() { video_mc.pause(); mc.visible = false; pn = new it.sephiroth.PrintScreen(); pn.addListener(listener); pn.print(this, 0, 0, 380, 200); loader.__set__label("Codificando... 0%"); loader.open(true, true, true); } // End of the function var loader = this.createClassObject(it.sephiroth.mloaderWindow, "loader", 10, {_x: -1000, _y: -1000}); loader.setStyle("borderColor", 26265); var listener = new Object(); listener.onProgress = function (target, loaded, total) { var _loc1 = Math.round(loaded / total * 100); loader.__set__label("exportando... " + _loc1 + "%"); loader.__set__value(_loc1); }; listener.onComplete = function (target, load_var) { loader.__set__label("sending to php..."); load_var.send("pixels.php", "_blank", "POST"); loader.close(); }; this.createEmptyMovieClip("mc", this.getNextHighestDepth()); mc.beginFill(16711680); mc.moveTo(0, 0); mc.lineTo(100, 0); mc.lineTo(100, 80); mc.lineTo(0, 80); mc.lineTo(0, 0); mc.endFill(); mc._x = 0; mc._y = 0; mc.visible = true; mc.loadMovie("FI2_Angular.swf"); var cmx = mc._x; var cmx = mc._y; dummy.onMouseDown = function () { this.lineStyle(5, 26265, 100, true, "normal", "round", "round", 4); this.moveTo(_xmouse, _ymouse); this.onMouseMove = function () { this.lineTo(_xmouse, _ymouse); updateAfterEvent(); }; this.onMouseUp = function () { delete this.onMouseMove; }; }; dummy.filters = [new flash.filters.BlurFilter(3, 3, 3)];
clase
Código :
import flash.display.BitmapData; import flash.geom.Rectangle; import flash.geom.ColorTransform; import flash.geom.Matrix; /** * Little and simple print flash screen class */ class it.sephiroth.PrintScreen { public var addListener:Function public var broadcastMessage:Function private var id: Number; public var record:LoadVars; function PrintScreen(){ AsBroadcaster.initialize( this ); } public function print(mc:MovieClip, x:Number, y:Number, w:Number, h:Number){ broadcastMessage("onStart", mc); if(x == undefined) x = 0; if(y == undefined) y = 0; if(w == undefined) w = mc._width; if(h == undefined) h = mc._height; var bmp:BitmapData = new BitmapData(w, h, false); record = new LoadVars(); record.width = w record.height = h record.cols = 0 record.rows = 0 var matrix = new Matrix(); matrix.translate(-x, -y) bmp.draw(mc, matrix, new ColorTransform(), 1, new Rectangle(0, 0, w, h)); id = setInterval(copysource, 5, this, mc, bmp); } private function copysource(scope, movie, bit){ var pixel:Number var str_pixel:String scope.record["px" + scope.record.rows] = new Array(); for(var a = 0; a < bit.width; a++){ pixel = bit.getPixel(a, scope.record.rows) str_pixel = pixel.toString(16) if(pixel == 0xFFFFFF) str_pixel = ""; // don't send blank pixel scope.record["px" + scope.record.rows].push(str_pixel) } scope.broadcastMessage("onProgress", movie, scope.record.rows, bit.height) // send back the progress status scope.record.rows += 1 if(scope.record.rows >= bit.height){ clearInterval(scope.id) scope.broadcastMessage("onComplete", movie, scope.record) // completed! bit.dispose(); } } }
php
Código :
<?php error_reporting(0); /** * Get the width and height of the destination image * from the POST variables and convert them into * integer values */ $w = (int)$_POST['width']; $h = (int)$_POST['height']; // create the image with desired width and height $img = imagecreatetruecolor($w, $h); // now fill the image with blank color // do you remember i wont pass the 0xFFFFFF pixels // from flash? imagefill($img, 0, 0, 0xFFFFFF); $rows = 0; $cols = 0; // now process every POST variable which // contains a pixel color for($rows = 0; $rows < $h; $rows++){ // convert the string into an array of n elements $c_row = explode(",", $_POST['px' . $rows]); for($cols = 0; $cols < $w; $cols++){ // get the single pixel color value $value = $c_row[$cols]; // if value is not empty (empty values are the blank pixels) if($value != ""){ // get the hexadecimal string (must be 6 chars length) // so add the missing chars if needed $hex = $value; while(strlen($hex) < 6){ $hex = "0" . $hex; } // convert value from HEX to RGB $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); // allocate the new color // N.B. teorically if a color was already allocated // we dont need to allocate another time // but this is only an example $test = imagecolorallocate($img, $r, $g, $b); // and paste that color into the image // at the correct position imagesetpixel($img, $cols, $rows, $test); } } } // print out the correct header to the browser header("Content-type:image/jpeg"); // display the image imagejpeg($img, "", 90); ?>
luego creando un boton que ejecute la accion me genera la imagen, la misma tarda mucho en generarse y es bastante tedioso, pero ese no es el problema sino que para aplicarlo sobre un telefono movil es muy complicado ya que son muy pocos los que soportan flash.
Ahora mi pregunta es: Hay alguna forma de generar un jpg de un flash emulando desde el servidor la accion.
Es un problema que me esta torturando, agradeceria cualquier comentario.
La imgen del grafico tiene que ser igual a la de la pagina. gracias