Ultrashock Forums > Flash > ActionScript
AS3 - Webcam snapshot

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
AS3 - Webcam snapshot
Old 2008-05-16

I have followed Lee's tutorials on saving snapshot from webcam, but now I found out that I need it to be in a normal swf file rather than an air application. How could I change the code here?
ActionScript Code:
  1. import com.adobe.images.PNGEncoder;
  2. import flash.filesystem.*;
  3.  
  4. var cam:Camera = Camera.getCamera();
  5. var video:Video = new Video(240,180);
  6.  
  7. cam.setQuality(0, 100);
  8.  
  9. video.attachCamera(cam);
  10. //video.x = -52.5;
  11. frame.addChild(video);
  12.  
  13. btn.addEventListener(MouseEvent.CLICK,saveImage);
  14.  
  15. var count:int = 0;
  16. //how to start from last number;
  17.  
  18. var scale:Number = .45;
  19.  
  20. var m:Matrix = new Matrix();
  21. m.scale(scale,scale);
  22.  
  23. function saveImage(e:MouseEvent):void {
  24.     var bmd:BitmapData = new BitmapData(60,80,false);
  25.     bmd.draw(video,m);
  26.     var ba:ByteArray = PNGEncoder.encode(bmd);
  27.     var file:File = File.desktopDirectory.resolvePath("card" + count++ +".png" );
  28.     var fileStream:FileStream = new FileStream();
  29.     fileStream.open(file,FileMode.WRITE);
  30.     fileStream.writeBytes(ba);
  31.     fileStream.close();
  32. }
I wanted to save the snapshot to a folder where my swf is.
Currently the code save the picture from 0 every time i open the swf. How can I save the filename after the last image in that folder?
postbit arrow Be the first to comment! | 5969 views postbit arrow Reply: with Quote   
Registered User
youwh is offline
seperator
Posts: 13
2005-12-29
seperator
Thread Tools
Display Modes Rate This Thread
Rate This Thread: