flex+php online photo
<?xml version= "1.0" encoding= "Utf-8"?>
<mx:application xmlns:mx= "Http://www.adobe.com/2006/mxml" layout= "absolute" width= "100%" xmlns:ns1= "*" Backgroundgradientcolors= "[#ecf9ff, #ecf9ff]" height= "100%" xmlns:ns2= "view.*" creationcomplete= "Initapp ()" >
<mx:Style>
alert{font-size:12px;}
</mx:Style>
<mx:Script>
<! [cdata[
Import mx.events.CloseEvent;
Import mx.rpc.events.FaultEvent;
Import mx.rpc.events.ResultEvent;
Import Mx.controls.Alert;
Import Mx.managers.CursorManager;
private static Const Default_camera_width:number = 160; Camera Display width
private static Const Default_camera_height:number = 120; Camera Display Height
private static Const Default_webservice_url:string = "Http://localhost:1888/Web/TestWebService.asmx?WSDL"; WebService address
private Var M_camera:camera; Define a camera
private Var M_localvideo:video; Define a local video
private var m_picturebitmapdata:bitmapdata//definition video screenshot
private Var Pic_width:int;
private Var Pic_height:int;
[bindable]
private Var m_picturedata:string;
Private Function Initapp (): void
{
t_btn_shooting.enabled = false;
t_ban_save.enabled = false;
Initcamera ();
Pic_height=m_camera.height;
Pic_width=m_camera.width;
}
Initializing the camera
Private Function Initcamera (): void
{
M_camera = Camera.getcamera ();
if (M_camera!= null)
{
M_camera.addeventlistener (Statusevent.status,__oncamerastatushandler);
M_camera.setmode (default_camera_width,default_camera_height,30);
M_localvideo = new video ();
M_localvideo.width = Default_camera_width;
M_localvideo.height = Default_camera_height;
M_localvideo.attachcamera (M_camera);
T_vd_video.addchild (M_localvideo);
}
Else
{
Alert.show ("No camera found, do you want to search again?") "," Hint: ", alert.ok| Alert.no,this,__initcamera);
Return
}
}
Photo button event, video screenshot
Private Function Snapshotpicture (): void
{
M_picturebitmapdata = new BitmapData (default_camera_width,default_camera_height);
M_picturebitmapdata.draw (T_vd_video,new Matrix ());
var m_picturebitmap:bitmap = new Bitmap (m_picturebitmapdata);
T_img_picture.addchild (M_PICTUREBITMAP);
T_panel_picture.visible = true;
T_ban_save.enabled = true;
}
Save the button event, save the video screenshot
Save by WebService
Private Function SavePicture (): void
{
M_picturedata = "";
M_picturebitmapdata.setpixel (1,1,6558750);
Label1.text=m_picturebitmapdata.getpixel (1,1). toString ();
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);
T_ws_SavePicture.SavePicture.send ();
}
Internal function Faulthandler (evt:faultevent): void{
labelresult.text= "Error";
Cursormanager.removebusycursor ();
Alert.show ("Save Error", "hint", alert.yes,this);
}
Internal function CreateImage (evt:resultevent): void{
Dg_article.dataprovider=evt.result;
Cursormanager.removebusycursor ();
Alert.show ("Save Success", "hint", alert.yes,this);
var date:date=new date ();
This.left.headerphoto.source= "yun_qi_img/0.jpg?id=" +date.getmilliseconds ();
}
Detect Camera Permission Events
Private Function __oncamerastatushandler (event:statusevent): void
{
if (!m_camera.muted)
{
T_btn_shooting.enabled = true;
}
Else
{
Alert.show ("Cannot link to the active camera, check again.") "," Hint: ", alert.ok| Alert.no,this,__initcamera);
}
M_camera.removeeventlistener (Statusevent.status,__oncamerastatushandler);
}
Retrieve the camera when it does not exist, or if the connection is not normal
Private Function __initcamera (event:closeevent): void
{
if (Event.detail = = Alert.ok)
{
Initapp ();
}
}
]]>
</mx:Script>
<mx:remoteobject id= "service" fault= "Faulthandler (event)" showbusycursor= "true"
Source= "image" destination= "amfphp" >
<!--define remote methods-->
<mx:method name= "Createjpeg" result= "CreateImage (event)"/>
</mx:RemoteObject>
<ns1:header x= "137" y= "ten" >
</ns1:header>
<NS1:LEFT1 x= "137" y= "158" id= "left" >
</ns1:left1>
<mx:panel x= "406" y= "158" width= "180" height= "232" layout= "absolute" title= "video Camera" fontsize= ">"
<mx:videodisplay id= "T_vd_video" width= "160" height= "146"/>
<mx:controlbar horizontalalign= "Right" >
<mx:button id= "t_btn_shooting" label= "photo" click= "snapshotpicture ()"/>
</mx:ControlBar>
</mx:Panel>
<mx:panel id= "T_panel_picture" x= "647" y= "158" width= "180" height= "232" layout= "absolute" title= "photo picture" fontSize= "12 "Visible= false" >
<mx:image id= "t_img_picture" x= "0" y= "0" width= "160" height= "144"/>
<mx:controlbar horizontalalign= "Right" >
<mx:button id= "T_ban_save" label= "Save" click= "SavePicture ()"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
Draw Avatar File:
<?php
Class image{
Public Function Createjpeg ($width, $height, $bitmap _data)
{
$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;
}
}
?>