Skip to main content
Participant
August 16, 2012
Answered

programmatically take picture after every 5 seconds on mobile phone

  • August 16, 2012
  • 3 replies
  • 3834 views

Hi, can anyone please tell me how to capture a picture programmatically after every 5 seconds. I can attach a camera to a Video component which i have added to my display list. Now once the user presses a button the app should start collecting the snap shot data every 5 seconds.

I DO NOT want to launch the native cameraUI app , all this should be from within my app.

I have the camera display visible in my app but how to issue the takepicture command??

thank you

This topic has been closed for replies.
Correct answer seilz2k

Simply take a snapshot form your video object by drawing it to a bitmapdata.

Follow this link:

http://stackoverflow.com/questions/10902472/take-a-picture-of-current-image-from-webcam-in-flash-as3

To trigger thaking snapshots every 5 seconds use the Timer class.

hope that helps

[damn it 4 minutes to late ]

3 replies

seilz2kCorrect answer
Inspiring
August 17, 2012

Simply take a snapshot form your video object by drawing it to a bitmapdata.

Follow this link:

http://stackoverflow.com/questions/10902472/take-a-picture-of-current-image-from-webcam-in-flash-as3

To trigger thaking snapshots every 5 seconds use the Timer class.

hope that helps

[damn it 4 minutes to late ]

Participating Frequently
August 17, 2012

For the every 5 seconds part, you can use the Timer class.

http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/utils/Timer.html

Or you can listen for enterFrame events and use a counter depending on your fps.

For the picutre capturing part, the simpliest way is probably

BitmapData.draw(yourCameraObject);

http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/display/BitmapData.html

Not sure if you want to save those bitmaps or not. I don't know the methods for that myself but if you need more info I suggest you specify the details so other people can help you easier. Things like save location (CameraRoll, app directory, cloud, etc),  and if you want to convert the pics to another format, etc.

Good luck

Participant
August 17, 2012

thanks a lot, got it working using

var bitmapData:BitmapData = new BitmapData(400, 300);

                bitmapData.draw(_video);  

where video is the Video instance.

to save the pics to the sdcard do the following :

make an array named imgBytesArray and periodically push into it "bitmapData" that you obtained in previous lines of code. At the end you need to encode this data to jpeg format and save it using this :

for(var i:int= imgBytesArray.length; i >0 ; i--)

                {

                    var file:File = File.documentsDirectory.resolvePath("DeviceApp/"+"num" + i + ".jpg");               

                    var stream:FileStream = new FileStream()

                    stream.open(file, FileMode.WRITE);                       

                    var encoder:JPEGEncoder = new JPEGEncoder();

                    var byteArray:ByteArray = encoder.encode(imgBytesArray.pop());   

                    stream.writeBytes(byteArray, 0, byteArray.bytesAvailable);

                    stream.close();

                }

this will save all your images under a folder mnt/sdcard/DeviceApp

hope it helps someone.