Heim > php教程 > php手册 > Hauptteil

flex+php在线拍照二

WBOY
Freigeben: 2016-06-13 11:21:32
Original
1123 Leute haben es durchsucht

flex+php在线拍照



 
    <script><br>                    import mx.events.CloseEvent;<br>            import mx.rpc.events.FaultEvent;<br>            import mx.rpc.events.ResultEvent;<br>            import mx.controls.Alert;<br>             import mx.managers.CursorManager;<br>            private static const DEFAULT_CAMERA_WIDTH:Number = 160; //摄像头显示宽度<br>            private static const DEFAULT_CAMERA_HEIGHT:Number = 120; //摄像头显示高度<br>            private static const DEFAULT_WEBSERVICE_URL:String = "http://localhost:1888/Web/TestWebService.asmx?WSDL"; //WebService地址<br>            <br>            private var m_camera:Camera; //定义一个摄像头<br>            private var m_localVideo:Video; //定义一个本地视频<br>            private var m_pictureBitmapData:BitmapData //定义视频截图<br>            private var pic_width:int;<br>            private var pic_height:int;<br>            //[Bindable]<br>            private var m_pictureData:String;<br>            <br>            private function initApp():void<br>            {<br>                t_btn_Shooting.enabled = false;<br>                t_ban_Save.enabled = false;<br>                initCamera();<br>               pic_height=m_camera.height;<br>               pic_width=m_camera.width;<br>            }<br>            <br>            //初始化摄像头<br>            private function initCamera():void<br>            {<br>                m_camera = Camera.getCamera();<br>                if(m_camera != null)<br>                {<br>                    m_camera.addEventListener(StatusEvent.STATUS,__onCameraStatusHandler);<br>                    <br>                    m_camera.setMode(DEFAULT_CAMERA_WIDTH,DEFAULT_CAMERA_HEIGHT,30);<br>                    m_localVideo = new Video();<br>                    m_localVideo.width = DEFAULT_CAMERA_WIDTH;<br>                    m_localVideo.height = DEFAULT_CAMERA_HEIGHT;<br>                    m_localVideo.attachCamera(m_camera);<br>                    t_vd_Video.addChild(m_localVideo);<br>                }<br>                else<br>                {<br>                    Alert.show("没有找到摄像头,是否重新查找。","提示:",Alert.OK|Alert.NO,this,__InitCamera);<br>                    return;<br>                }<br>            }<br>            <br>            //拍照按钮事件,进行视频截图<br>            private function SnapshotPicture():void<br>            {<br>                m_pictureBitmapData = new BitmapData(DEFAULT_CAMERA_WIDTH,DEFAULT_CAMERA_HEIGHT);<br>                m_pictureBitmapData.draw(t_vd_Video,new Matrix());<br>                <br>                var m_pictureBitmap:Bitmap = new Bitmap(m_pictureBitmapData);<br>                t_img_Picture.addChild(m_pictureBitmap);<br>                <br>                t_panel_Picture.visible = true;<br>                t_ban_Save.enabled = true;<br>            }<br>            <br>            //保存按钮事件,保存视频截图<br>            //通过WebService保存<br>            private function SavePicture():void<br>            {<br>                m_pictureData = "";<br>                //m_pictureBitmapData.setPixel(1,1,6558750);<br>                //label1.text=m_pictureBitmapData.getPixel(1,1).toString();<br>                <br>                for(var i:int = 0; i                 {<br>                    for(var j:int = 0; j                     {<br>                        if(m_pictureData.length > 0)<br>                        {<br>                            m_pictureData += "," + m_pictureBitmapData.getPixel(i,j).toString();<br>                        }<br>                        else<br>                        {<br>                            m_pictureData = m_pictureBitmapData.getPixel(i,j).toString();<br>                        }<br>                    }<br>                }<br>                service.getOperation("createjpeg").send(pic_width,pic_height,m_pictureData);<br>               // t_ws_SavePicture.SavePicture.send();<br>               <br>            }<br>            internal function faultHandler(evt:FaultEvent):void{<br>   //labelresult.text="error";<br>   CursorManager.removeBusyCursor();<br>   Alert.show("保存出错","提示",Alert.YES,this);<br>   <br>  }<br>  internal function createImage(evt:ResultEvent):void{<br>      //dg_article.dataProvider=evt.result; <br>      CursorManager.removeBusyCursor();<br>   Alert.show("保存成功","提示",Alert.YES,this);<br>   var date:Date=new Date();<br>   this.left.headerphoto.source="http://www.tiyi88.com/image/header/0.jpg?id="+date.getMilliseconds();<br>  }<br>            //检测摄像头权限事件<br>            private function __onCameraStatusHandler(event:StatusEvent):void<br>            {<br>                if(!m_camera.muted)<br>                {<br>                    t_btn_Shooting.enabled = true;<br>                }<br>                else<br>                {<br>                    Alert.show("无法链接到活动摄像头,是否重新检测。","提示:",Alert.OK|Alert.NO,this,__InitCamera);<br>                }<br>                m_camera.removeEventListener(StatusEvent.STATUS,__onCameraStatusHandler);<br>            }<br>            <br>            //当摄像头不存在,或连接不正常时重新获取<br>            private function __InitCamera(event:CloseEvent):void<br>            {<br>                if(event.detail == Alert.OK)<br>                {<br>                    initApp();<br>                }<br>            }<br>        ]]><br>    </script>
                  source="image" destination="amfphp">
  
  
  
 


 

 
 
 
 
       
       
           
       

   

   
       
       
           
       

   

绘制头像文件:

class Image{
 
 public function createjpeg($width,$height,$bitmap_data)
 {
  $img=imagecreatetruecolor($width,$height);
  $m_tempPics=explode(',',$bitmap_data);
   for ($i = 0; $i             {
                for ($j = 0; $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;
 }
}
?>


Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage