flex+php線上拍照一[51空間]

來源:互聯網
上載者:User


昨天用flex+php做了一個線上拍照的小東東,可以實現會員頭像的即時線上拍照更新。
首先來講一講原理:
1、將camera的內容顯示在video中,這個不懂的參考actionscript的手冊,裡面有詳細的講解以及代碼,
2、定義一下BitmapData對象,
m_pictureBitmapData = new BitmapData(DEFAULT_CAMERA_WIDTH,DEFAULT_CAMERA_HEIGHT);
然後將video的內容寫進BitmapData對象裡, m_pictureBitmapData.draw(video,new Matrix());
3、從左至右,從上到下,一個像素一個像素的讀取BitmapData的rgb值,所有的rgb值用","分開,寫進一個字串裡,
for(var i:int = 0; i < DEFAULT_CAMERA_WIDTH; i++)
                {
                    for(var j:int = 0; j < DEFAULT_CAMERA_HEIGHT; j++)
                    {
                        if(m_pictureData.length > 0)
                        {
                            m_pictureData += "," + m_pictureBitmapData.getPixel(i,j).toString();
                        }
                        else
                        {
                            m_pictureData = m_pictureBitmapData.getPixel(i,j).toString();
                        }
                    }
                }
                service.getOperation("createjpeg").send(pic_width,pic_height,m_pictureData);//用amfphp進行儲存
4、在服務端就把那些rgb值提取出來,一個像素一個像素的畫點:
$img=imagecreatetruecolor($width,$height);
  $m_tempPics=explode(',',$bitmap_data);
   for ($i = 0; $i < $width; $i++)
            {
                for ($j = 0; $j < $height; $j++)
                {
                    $pic_argb =(int) $m_tempPics[$i * $height + $j];
                    imagesetpixel($img,$i,$j,$pic_argb);
                }
            }
        imagejpeg($img,"../../image/header/0.jpg");
        imagedestroy($img);
        return true;
5、詳細的源碼在附件裡面,前面只是些重要提示代碼。嗯,要懂得amfphp,還有flex。
還有什麼不清楚的,
下面來看看 test.html檔案
if ( hasProductInstall && !hasRequestedVersion ) {
 // MMdoctitle is the stored document.title value used by the installation process to close the window that started the process
 // This is necessary in order to close browser windows that are still utilizing the older version of the player after installation has completed
 // DO NOT MODIFY THE FOLLOWING FOUR LINES
 // Location visited after installation is complete if installation is required
 var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
 var MMredirectURL = window.location;
    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
    var MMdoctitle = document.title;
 AC_FL_RunContent(
  "src", "playerProductInstall",
  "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
  "width", "100%",
  "height", "100%",
  "align", "middle",
  "id", "hphoto",
  "quality", "high",
  "bgcolor", "#869ca7",
  "name", "hphoto",
  "allowScriptAccess","sameDomain",
  "type", "application/x-shockwave-flash",
  "pluginspage", "http://www.adobe.com/go/getflashplayer"
 );
} else if (hasRequestedVersion) {
 // if we've detected an acceptable version
 // embed the Flash Content SWF when all tests are passed
 AC_FL_RunContent(
   "src", "hphoto",
   "width", "100%",
   "height", "100%",
   "align", "middle",
   "id", "hphoto",
   "quality", "high",
   "bgcolor", "#869ca7",
   "name", "hphoto",
   "flashvars",'historyUrl=history.htm%3F&lconid=' + lc_id + '',
   "allowScriptAccess","sameDomain",
   "type", "application/x-shockwave-flash",
   "pluginspage", "http://www.adobe.com/go/getflashplayer"
 );
  } else {  // flash is too old or we can't detect the plugin
    var alternateContent = 'Alternate HTML content should be placed here. '
   + 'This content requires the Adobe Flash Player. '
    + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
    document.write(alternateContent);  // insert non-flash content
  }
// -->
</script>
<noscript>
   <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
   id="hphoto" width="100%" height="100%"
   codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
   <param name="movie" value="hphoto.swf" />
   <param name="quality" value="high" />
   <param name="bgcolor" value="#869ca7" />
   <param name="allowScriptAccess" value="sameDomain" />
   <embed src="hphoto.swf" quality="high" bgcolor="#869ca7"
    width="100%" height="100%" name="hphoto" align="middle"
    play="true"
    loop="false"
    quality="high"
    allowScriptAccess="sameDomain"
    type="application/x-shockwave-flash"
    pluginspage="http://www.adobe.com/go/getflashplayer">
   </embed>
 </object>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.