Comunidad de diseño web y desarrollo en internet online

Ayuda con aplicacion Movil

Citar            
MensajeEscrito el 08 Jul 2008 05:31 pm
Hola a todos, es mi primer pregunto, despues de tanto consultar con sus respuestas me decidi a hacer una pregunta sobre un proyecto que estoy haciendo.

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

Por ctv

2 de clabLevel



Genero:Masculino  

Argentina

firefox
Citar            
MensajeEscrito el 08 Jul 2008 06:16 pm

AXM escribió:

Mira este codigo. Es una aplicación en flex, que hace eso. nos lo enseño Freddie. Lo que necesitas lo haces con FileReference.

Código :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="inicio();" layout="absolute" backgroundGradientColors="[#0080ff, #004993]" >
<mx:Script>
 <![CDATA[
 import flash.net.FileReference;
 import flash.events.*;
 import mx.events.*;
 import mx.managers.CursorManager;
 import mx.controls.Alert;
  
 private var ftp:FileReference = new FileReference();

 
 private function inicio():void
 {
  ftp.addEventListener(Event.SELECT, subamos);
   ftp.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, cargaCompleta);
  archivos.send();
  
 }  
 
 private function abrir(e:MouseEvent):void
 {
  ftp.browse([new FileFilter("solo Imagenes", "*jpg;*.gif;*.png"), new FileFilter("Lo que sea", "*")]);
 }
 private function subamos(e:Event):void
 {
  ftp.upload ( new URLRequest("http://172.16.4.85/taller/subir/subidor.php"));
  CursorManager.setBusyCursor();

 }
 private function cargaCompleta(e:DataEvent):void
 {
  CursorManager.removeBusyCursor();
  Alert.show("Carga Completa");
 }  

 ]]>
</mx:Script>


 <mx:HTTPService id="archivos" url="http://172.16.4.85/taller/subir/lista.php"/>
 <mx:Panel layout="absolute" top="10" width="639" height="426" title="Sistema FTP" cornerRadius="20" horizontalCenter="0">
  <mx:DataGrid left="10" top="10" bottom="40" right="10" id="lista" dataProvider="{archivos.lastResult.files.file}">
   <mx:columns>
    <mx:DataGridColumn headerText="Nombre" dataField="name"/>
    <mx:DataGridColumn headerText="Tamaño" dataField="tamanio"/>
   </mx:columns>
  </mx:DataGrid>
  <mx:Button label="Bajar" bottom="10" left="73" id="bajar"/>
  <mx:Button label="Subir" bottom="10" left="10" id="subir" click="abrir(event);"/>
  <mx:ProgressBar right="10" bottom="10" id="barra" minimum="0" maximum="100"/>
 </mx:Panel>
 
</mx:Application>


algo asi necesitaria, les comento que estoy empezando con programacion, solo quiero saber si hay alguna forma de encararlo por este lado, por lo general me encargo del diseño de paginas y animaciones, pero siempre aplicando algo de programacion y cada vez un poco mas pero esto seria la mayoria programacion y es atractivo. Gracias

Por ctv

2 de clabLevel



Genero:Masculino  

Argentina

firefox

 

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