# Webcam snapshot

**URL:** <https://forum.kirupa.com/t/webcam-snapshot/260586>\
**Category:** flash\
**Created:** [May 17, 2008, 12:02am UTC](https://forum.kirupa.com/t/webcam-snapshot/260586 "2008-05-17T00:02:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![youwh](https://avatars.discourse-cdn.com/v4/letter/y/82dd89/32.png) [@youwh](https://forum.kirupa.com/u/youwh)\
**Post date:** [May 17, 2008, 12:02am UTC](https://forum.kirupa.com/t/webcam-snapshot/260586/1 "2008-05-17T00:02:34Z")

</div>

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?

```auto

import com.adobe.images.PNGEncoder;
import flash.filesystem.*;

var cam:Camera = Camera.getCamera();
var video:Video = new Video(240,180);

cam.setQuality(0, 100);

video.attachCamera(cam);
//video.x = -52.5;
frame.addChild(video);

btn.addEventListener(MouseEvent.CLICK,saveImage);

var count:int = 0;
//how to start from last number;

var scale:Number = .45;

var m:Matrix = new Matrix();
m.scale(scale,scale);

function saveImage(e:MouseEvent):void {
    var bmd:BitmapData = new BitmapData(60,80,false);
    bmd.draw(video,m);
    var ba:ByteArray = PNGEncoder.encode(bmd);
    var file:File = File.desktopDirectory.resolvePath("card" + count++ +".png" );
    var fileStream:FileStream = new FileStream();
    fileStream.open(file,FileMode.WRITE);
    fileStream.writeBytes(ba);
    fileStream.close();
}

```

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?

---

<div class="post-metadata">

**Author:** ![Groady](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/groady/32/3750_2.png) [@Groady](https://forum.kirupa.com/u/Groady)\
**Post date:** [May 17, 2008, 6:40am UTC](https://forum.kirupa.com/t/webcam-snapshot/260586/2 "2008-05-17T06:40:56Z")

</div>

You won’t be able to save an image out of flash to the filesystem if it’s not an AIR application.

---

<div class="post-metadata">

**Author:** ![youwh](https://avatars.discourse-cdn.com/v4/letter/y/82dd89/32.png) [@youwh](https://forum.kirupa.com/u/youwh)\
**Post date:** [May 17, 2008, 8:01am UTC](https://forum.kirupa.com/t/webcam-snapshot/260586/3 "2008-05-17T08:01:15Z")

</div>

Can the air run on9? And like save it to server?

---

<div class="post-metadata">

**Author:** ![Groady](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/groady/32/3750_2.png) [@Groady](https://forum.kirupa.com/u/Groady)\
**Post date:** [May 18, 2008, 1:09pm UTC](https://forum.kirupa.com/t/webcam-snapshot/260586/4 "2008-05-18T13:09:23Z")

</div>

You can send a byte array to a server, yes. You will need to use [as3corelib to convert your bitmapdata into a jpeg. I use AMFPHP on my site [URL=“http://www.cellpaint.com”]cellpaint.com](http://code.google.com/p/as3corelib/) to ‘catch’ the bytearray and write it to the server.
