Flash/flex Study Notes (5): capture the camera (continued)-capture the screen online and save it to the client

Source: Internet
Author: User

A camera is required for normal playback.

Ideas:

Using the camera and online screen capture in the previous Flash/flex learning note (2): capture the camera has already been mentioned, so do not paste it again. As for saving files on the client, flash is also very simple to use: directly call filereference can be, in order to reduce the image size, may also use as3.0 extension Library (Project address http://code.google.com/p/as3corelib ), convert the location of the BMP format to JPEG and save it.

 

Extension:

Combined with the methods described in this article and the flash/flex learning notes (4): how to open a webpage and get/post data, you can easily make "online dashboard" or "online generation of membership headers" and other functions.

Source code:

 

VaR W: Int = stage. stagewidth; // original scene width var H: Int = stage. stageheight; // The original height of the scene stage. scalemode = stagescalemode. no_scale; // The stage cannot be scaled, but does it seem ineffective? VaR video: Video; var camera: Camera = camera. getcamera (); // get the camera lblauthor. addeventlistener (mouseevent. click, function () {navigatetoURL (New URLRequest ("http://www.cnblogs.com/yjmyzz"), "_ blank")}); // detect the camera if (CAMERA = NULL) {trace ("no camera detected! "); Lbl1.text =" no camera detected! "; Btncapture. visible = false; tilelst1.visible = false; lblmemo. visible = false;} else {Camera. addeventlistener (activityevent. activity, activityhander); video = new video (camera. width, camera. height); trace ("video width:" + camera. width + ", video Height:" + camera. height); video. attachcamera (CAMERA); // locate the horizontal center point video. X = (W-video. width)/2; video. y = 10; addchild (video); // load it to the current stage. X = (W-btncapture. width)/2; btncapture. y = video. Y + video. height + 5; btncapture. addeventlistener (mouseevent. click, captureimage);} // detects camera activity changes. Function activityhander (E: activityevent): void {trace ("activityhander:" + E);} var DP: dataprovider = new dataprovider (); tilelst1.addeventlistener (mouseevent. click, saveimage); // double-click to save to the local function saveimage (E: mouseevent) {If (e.tar get. hasownproperty ("Source") {// check that the VaR worker Encoder: jpgencoder = new jpgencoder () is saved only when the image is clicked. var bitmap: bitmap = e.tar get. data. source; var incluarr: bytearray = incluencoder. encode (bitmap. bitmapdata); // compressed into JPEG trace (jpegarr. length); var file: filereference = new filereference (); var filename: String = e.tar get. data. label + ". jpg "; // set the file name. save (jpegarr, filename); // save to local} // video processing function captureimage (E: mouseevent): void {// trace ("You clicked the button "); vaR bit: bitmapdata = new bitmapdata (video. width, video. height); bit. draw (video); var BMP: bitmap = new Bitmap (BIT); var D: Date = new date (); DP. additem ({label: "" + D. getfullyear () + d. getmonth () + d. getday () + d. gethours () + d. getminutes () + d. getseconds () + d. getmilliseconds (), source: BMP}); tilelst1.dataprovider = DP; trace (DP. length); tilelst1.scrolltoindex (DP. length-1); // the scroll bar is automatically pulled to the last image} STOP ();

sample source Code download: http://cid-2959920b8267aaca.skydrive.live.com/self.aspx/Flash/GetCamera2.rar

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.