1.Flash端,通过adobe的类包,将BitmapData数据Encoder成ByteArray .然后,通过http或者amfphp发送到服务器端。
Code:
var bd:BitmapData = new   BitmapData(canvas.width,canvas.height);
bd.draw(canvas); 
var jpgEncoder : PNGEncoder = new PNGEncoder(); 
var jpgBytes:ByteArray = PNGEncoder.encode(bd);

2.服务端的工作(针对amfphp而言):接受ByteArray ,注意,php是直接支持ByteArray类型的,然后通过fwrite或者file_put_contents,写数据,并且输出文件,ok搞定
Code:
public function createSavePngFile($ba,$savePoint)
{
       date_default_timezone_set('Asia/Shanghai');
  
       $now = date("YmdHis"); 
       $path = "resource/shareVideo/"; 
       $fileName = $path.$now.".png";
       $data = $ba->data;
   
       if(!file_exists($path.$now.".png"))
       {         
             $input = file_put_contents( $fileName, $data);//写入二进制数据
    
              if($input != 0 && $input != -1)
             {
                   return $this->serverPoxy->updateShareInfo($savePoint,$fileName);
            }
             else
            {
                   return false;
            }
       }
      return false;
}
注意:file_put_contents( $fileName, $data);中第二个参数是:$ba->data,而不是$ba,这是php的数据结构的规范。
附上关于AMFPHP网站的参考资料:
Send and Receive ByteArray to AMFPHP(http://www.sephiroth.it/tutorials/flashPHP/amfphp_bytearray/
Code:
<?php

class SaveJPEG
{
     var 
$output_dir "temp";
     var 
$server_url "http://www.sephiroth.it/amfphp2/services/tutorials/amfphp_bytearray/";

    
/**
      * Save image from the given bytearray
      * and return the path of the saved image
      */
    
function SaveAsJPEG($ba$compressed false)
     {
         if(!
file_exists($this->output_dir) || !is_writeable($this->output_dir))
            
trigger_error ("please create a 'temp' directory first with write access"E_USER_ERROR);

        
$data $ba->data;
         if(
$compressed)
         {
             if(
function_exists(gzuncompress))
             {
                
$data gzuncompress($data);
             } else {
                
trigger_error ("gzuncompress method does not exists, please send uncompressed data"E_USER_ERROR);
             }
         }
        
file_put_contents($this->output_dir "/rawdata.jpeg"$data);
         return 
$this->server_url $this->output_dir "/rawdata.jpeg";
     }

    
/**
      * Save file from a given bytearray
      * and return a ByteArray from the saved file
      */
    
function SaveAsByteArray($ba$compresses false)
     {
         if(!
file_exists($this->output_dir) || !is_writeable($this->output_dir))
            
trigger_error ("please create a 'temp' directory first with write access"E_USER_ERROR);

        
$data $ba->data;
         if(
$compressed)
         {
             if(
function_exists(gzuncompress))
             {
                
$data gzuncompress($data);
             } else {
                
trigger_error ("gzuncompress method does not exists, please send uncompressed data"E_USER_ERROR);
             }
         }
        
file_put_contents($this->output_dir "/rawdata.rgb"$data);
         return new 
ByteArray(file_get_contents($this->output_dir "/rawdata.rgb"));
     }
}

?>

Trackback

Tags:

共0评论

发表评论

最新评论及回复

最近发表

网站分类

文章归档

友情链接