Flex + php online photo 2

Source: Internet
Author: User
Tags php online

Flex + php online photo taking

<? 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; // The height of the camera.
Private static const DEFAULT_WEBSERVICE_URL: String = "http: // localhost: 1888/Web/TestWebService. asmx? WSDL "; // WebService address

Private var m_camera: Camera; // defines a Camera.
Private var m_localVideo: Video; // defines a local Video.
Private var m_pictureBitmapData: BitmapData // defines the video
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;
}

// Initialize 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 ("the camera is not found. Check whether to find the camera again. "," Prompt: ", Alert. OK | Alert. NO, this ,__ InitCamera );
Return;
}
}

// Video taking button event
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 and save the video
// Save through WebService
Private function SavePicture (): void
{
M_pictureData = "";
// M_pictureBitmapData.setPixel (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 ("saving error", "prompt", Alert. YES, this );

}
Internal function createImage (evt: ResultEvent): void {
// Dg_article.dataProvider = evt. result;
CursorManager. removeBusyCursor ();
Alert. show ("saved successfully", "prompt", Alert. YES, this );
Var date: Date = new Date ();
This. left. headerphoto. source = "http://www.tiyi88.com/image/header/0.jpg? Id = "+ date. getMilliseconds ();
}
// Detects camera permission events
Private function _ onCameraStatusHandler (event: StatusEvent): void
{
If (! M_camera.muted)
{
T_btn_Shooting.enabled = true;
}
Else
{
Alert. show ("unable to link to the active camera, whether to re-detect. "," Prompt: ", Alert. OK | Alert. NO, this ,__ InitCamera );
}
M_camera.removeEventListener (StatusEvent. STATUS ,__ onCameraStatusHandler );
}

// Re-obtain the camera if it does not exist or the connection is abnormal
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 a remote method -->
<Mx: method name = "createjpeg" result = "createImage (event)"/>
</Mx: RemoteObject>
<Ns1: header x = "137" y = "10">
</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 = "12">
<Mx: VideoDisplay id = "t_vd_Video" width = "160" height = "146"/>
<Mx: ControlBar horizontalAlign = "right">
<Mx: Button id = "t_btn_Shooting" label = "" click = "SnapshotPicture ()"/>
</Mx: ControlBar>
</Mx: Panel>
<Mx: panel id = "t_panel_Picture" x = "647" y = "158" width = "180" height = "232" layout = "absolute" title = "photo image" 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>

Create an 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;
}
}
?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.