Capturing images in Flex 2 is actually very simple.

Source: Internet
Author: User
Tags addchild xmlns

Capturing the image in Flex 2 is actually very simple, but before you accidentally see an example on the network (but I forgot where: P), but that doesn't matter, I did a similar example, the principle is to create a ActionScript component, using Mxml to call this component, Of course you need a button to do this snapshot, and then real-time snapshot to the face version can be.

Direct Browsing Example: http://j2eemx.com/flex/webcam/webcam.html

All program code ...

An example of the ActionScript class file is as follows:

Package mycomponents
{
Import Mx.containers.Panel;
Import Flash.media.Camera;
Import Flash.media.Video;
Import mx.core.UIComponent;

public class Webcampanel extends Panel
{
public Var Video:video
Public Function Webcampanel () {
Super ();
Insertwebcamvideo ();
}
Public Function Insertwebcamvideo (): void{
var videoholder:uicomponent = new UIComponent ();
var Camera:camera = Camera.getcamera ();
Video = new Video (camera.width*2, camera.height*2);
Video.attachcamera (camera);
Videoholder.addchild (video);
AddChild (Videoholder);
VIDEOHOLDER.Y = 10;
}
}
}

The Webcam.mxml program code is as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<mx:application xmlns:mx= "Http://www.adobe.com/2006/mxml" xmlns:mycomp= "mycomponents.*" layout= "Absolute" &G T
<mx:Script>
<! [cdata[
Import mx.core.UIComponent;
Import Flash.display.BitmapData;

Snapshot functions
Public Function Takesnapshot (): void{
var snapshotholder:uicomponent = new UIComponent ();
var snapshot:bitmapdata = new BitmapData (+ +, true);
var snapshotbitmap:bitmap = new Bitmap (snapshot);
SNAPSHOTHOLDER.Y = 10;
Snapshotholder.addchild (SNAPSHOTBITMAP);
Pnlsnapshot.addchild (Snapshotholder);
Snapshot.draw (Pnlwebcam.video);
Pnlsnapshot.visible = true;
}
]]>
</mx:Script>

<!--initial image surface version-->
<mycomp:webcampanel x= "WU" y= "Wuyi" width= "360" height= "320"
layout= "Absolute" backgroundcolor= "#ffffff"
Backgroundalpha= "1.0" title= "This is a dynamic image."
Fontsize= "fontfamily=" "Verdana"
Color= "#000000" bordercolor= "#0080ff" borderstyle= "solid"
cornerradius= "0" barcolor= "#FFFFFF" borderthickness= "10"
Dropshadowcolor= "#FFFFFF" dropshadowenabled= "false"
footercolors= "#FFFFFF" headercolors= "#FFFFFF"
highlightalphas= "0" shadowdirection= "center"
Textalign= "Right" textdecoration= "none" borderalpha= "0"
Fontweight= "Bold" id= "Pnlwebcam" shadowdistance= "alpha=" >
</MyComp:WebcamPanel>

<!--image retrieval after the surface version-->
<mx:panel x= "499" y= "WU" width= "360" height= "" layout= "absolute"
Backgroundcolor= "#ffffff" backgroundalpha= "1.0"
Title= "This is the image capture" fontsize= "fontfamily=" Verdana "
Color= "#ff0080" bordercolor= "#ff0080" borderstyle= "solid"
cornerradius= "0" barcolor= "#FFFFFF" borderthickness= "10"
Dropshadowcolor= "#FFFFFF" dropshadowenabled= "false"
footercolors= "#FFFFFF" headercolors= "#FFFFFF"
highlightalphas= "0" shadowdirection= "right"
Textalign= "left" textdecoration= "none" borderalpha= "0"
Fontweight= "Bold" id= "Pnlsnapshot" visible= "false" >
</mx:Panel>

<!--button triggers snapshot image-->
<mx:button x= "y=" "379"
Bordercolor= "#FFFFFF" focusalpha= "1" color= "#ffffff"
Textrollovercolor= "#FFFFFF" textselectedcolor= "#000000"
Themecolor= "#0080ff" fillalphas= "[1.0, 1.0]"
Errorcolor= "#ff0080" fillcolors= "[#0080ff, #0080ff]"
Fontsize= "fontfamily=" "Verdana" fontweight= "bold"
cornerradius= "0" alpha= "1.0" click= "Takesnapshot ()" label= "Capture image"/>
<mx:label x= "y=" text= "Flex Demo from RiS http://j2eemx.com" fontsize= "a"/>
</mx:Application>


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.