Comunidad de diseño web y desarrollo en internet online

Problema con screenShot en AS3

Citar            
MensajeEscrito el 02 Ene 2012 09:06 am
Hola a todos, tengo un problemilla, a ver si alguien me puede echar un cable.
Resulta que tengo una "pizarra" echa en AS3 y Flash CS4 y al pulsar un botón hago un screenshot de la "pizarra" y deseo guardar la imagen resultante en una carpeta de mi servidor automáticamente, pero resulta que en lugar de esto sólo me permite descargarmela en mi PC.
Alguien sabe como puedo solventarlo?
Les dejo el trozo de código que estoy usando:

Código ActionScript :

private function imageCapture(target:DisplayObject):void {
        var saveHelper:FileReference = new FileReference();
   var fileName:String;
   var relative:DisplayObject = target.parent;
   var rect:Rectangle = target.getBounds(relative);

   var PIXEL_BUFFER:uint=1;
   // capture within bounding rectangle; add a 1-pixel buffer around the perimeter to ensure that all anti-aliasing is included
   var bitmapData:BitmapData = new BitmapData(rect.width + PIXEL_BUFFER * 2, rect.height + PIXEL_BUFFER * 2);
   // capture the target into bitmapData
   bitmapData.draw(relative, new Matrix(1, 0, 0, 1, -rect.x + PIXEL_BUFFER, -rect.y + PIXEL_BUFFER));
   // encode image to ByteArray
   var byteArray:ByteArray;
   imgCount++;

   fileName = "image_" + imgCount +".png";
   byteArray = PNGEncoder.encode(bitmapData);
         
   saveHelper.save(byteArray, fileName);
}


Muchas gracias por su tiempo.

Por Palacio

Claber

198 de clabLevel



 

firefox
Citar            
MensajeEscrito el 03 Ene 2012 12:21 am
En vez de save, deberías usar upload si lo que quieres es pasarlo al servidor. El problema es que el byteArray debe ser serializado y pasado a un script de servidor que lo guarde como archivo. mira si la clase PNGEncoder tiene alguna funcionalidad para eso

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 03 Ene 2012 08:11 am
Hola Jorge, muchas gracias por tu comentario, pero no sé como serializar un byteArray.
La clase PNGEncoder es la siguiente:

Código ActionScript :

package com.adobe.images
{
   import flash.geom.*;
   import flash.display.Bitmap;
   import flash.display.BitmapData;
   import flash.utils.ByteArray;

   /**
    * Class that converts BitmapData into a valid PNG
    */   
   public class PNGEncoder
   {
      /**
       * Created a PNG image from the specified BitmapData
       *
       * @param image The BitmapData that will be converted into the PNG format.
       * @return a ByteArray representing the PNG encoded image data.
       * @langversion ActionScript 3.0
       * @playerversion Flash 9.0
       * @tiptext
       */         
       public static function encode(img:BitmapData):ByteArray {
           // Create output byte array
           var png:ByteArray = new ByteArray();
           // Write PNG signature
           png.writeUnsignedInt(0x89504e47);
           png.writeUnsignedInt(0x0D0A1A0A);
           // Build IHDR chunk
           var IHDR:ByteArray = new ByteArray();
           IHDR.writeInt(img.width);
           IHDR.writeInt(img.height);
           IHDR.writeUnsignedInt(0x08060000); // 32bit RGBA
           IHDR.writeByte(0);
           writeChunk(png,0x49484452,IHDR);
           // Build IDAT chunk
           var IDAT:ByteArray= new ByteArray();
           for(var i:int=0;i < img.height;i++) {
               // no filter
               IDAT.writeByte(0);
               var p:uint;
               var j:int;
               if ( !img.transparent ) {
                   for(j=0;j < img.width;j++) {
                       p = img.getPixel(j,i);
                       IDAT.writeUnsignedInt(
                           uint(((p&0xFFFFFF) << 8)|0xFF));
                   }
               } else {
                   for(j=0;j < img.width;j++) {
                       p = img.getPixel32(j,i);
                       IDAT.writeUnsignedInt(
                           uint(((p&0xFFFFFF) << 8)|
                           (p>>>24)));
                   }
               }
           }
           IDAT.compress();
           writeChunk(png,0x49444154,IDAT);
           // Build IEND chunk
           writeChunk(png,0x49454E44,null);
           // return PNG
           return png;
       }
   
       private static var crcTable:Array;
       private static var crcTableComputed:Boolean = false;
   
       private static function writeChunk(png:ByteArray, 
               type:uint, data:ByteArray):void {
           if (!crcTableComputed) {
               crcTableComputed = true;
               crcTable = [];
               var c:uint;
               for (var n:uint = 0; n < 256; n++) {
                   c = n;
                   for (var k:uint = 0; k < 8; k++) {
                       if (c & 1) {
                           c = uint(uint(0xedb88320) ^ 
                               uint(c >>> 1));
                       } else {
                           c = uint(c >>> 1);
                       }
                   }
                   crcTable[n] = c;
               }
           }
           var len:uint = 0;
           if (data != null) {
               len = data.length;
           }
           png.writeUnsignedInt(len);
           var p:uint = png.position;
           png.writeUnsignedInt(type);
           if ( data != null ) {
               png.writeBytes(data);
           }
           var e:uint = png.position;
           png.position = p;
           c = 0xffffffff;
           for (var i:int = 0; i < (e-p); i++) {
               c = uint(crcTable[
                   (c ^ png.readUnsignedByte()) & 
                   uint(0xff)] ^ uint(c >>> 8));
           }
           c = uint(c^uint(0xffffffff));
           png.position = e;
           png.writeUnsignedInt(c);
       }
   }
}

Alguna idea? Estoy bastante perdido en este tema.
Muchas gracias

Por Palacio

Claber

198 de clabLevel



 

firefox
Citar            
MensajeEscrito el 03 Ene 2012 12:23 pm

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 04 Ene 2012 09:56 am
Muchas gracias Jorge, ahora me falta la parte del servidor, pero esto ya lo preguntaré en el foro correspondiente.

Por Palacio

Claber

198 de clabLevel



 

firefox

 

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