One more experiment, Colored Webcam
The BitmapData class is very cool. In this experiment the was used threshold method to accomplish the coloring of the image received of the webcam.
In case you have a webcam, below the video I put the file for you to see the experiment working.
The code of the application it's the end of the page, the code is commented on.
Colored Webcam
This movie requires Flash Player 8
Actionscript:
-
//importing the classes
-
import flash.display.*;
-
import flash.geom.*;
-
-
//Camera object
-
var camera:Camera = Camera.get();
-
//attach the Camera object in video object
-
mcCam.webcam.attachVideo(camera);
-
-
//BitmapData object of the final image
-
var imagem:BitmapData = new BitmapData(camera.width, camera.height, false, 0);
-
//BitmapData object that will contain the modified image
-
var imagemContainer:BitmapData = new BitmapData(camera.width, camera.height, false, 0);
-
-
//rectangle object, it defines the area of the image source in the threshold method
-
var retangulo = new Rectangle(0, 0, camera.width, camera.height);
-
//point object, the points correspond to the top-left of the image source in the threshold method
-
var ponto = new Point(0, 0);
-
-
//function that will draw the new image
-
function atualizarImagem():Void{
-
//he draws the image of the webcam in the BitmapData object
-
imagemContainer.draw(mcCam.webcam);
-
//through the threshold method the change of colors is accomplished
-
imagem.threshold(imagemContainer, retangulo, ponto, "<", 8000000, 0x006600, 0xFF0000, false);
-
imagem.threshold(imagemContainer, retangulo, ponto, ">", 8000000, 0xFF3333, 0xFF0000, false);
-
imagem.threshold(imagemContainer, retangulo, ponto, ">", 10000000, 0xFFFF66, 0xFF0000, false);
-
imagem.threshold(imagemContainer, retangulo, ponto, ">", 12000000, 0x99FF66, 0xFF0000, false);
-
imagem.threshold(imagemContainer, retangulo, ponto, ">", 15000000, 0xFFFFFF, 0xFF0000, false);
-
};
-
-
//movieclip to store the modified images
-
this.createEmptyMovieClip('mcCamModificado', this.getNextHighestDepth());
-
mcCamModificado._x = 20;
-
mcCamModificado._y = mcCam._y + mcCam._height + 20;
-
-
//first modified image
-
mcCamModificado.createEmptyMovieClip('cam1', mcCamModificado.getNextHighestDepth());
-
mcCamModificado.cam1.attachBitmap(imagem, mcCamModificado.getNextHighestDepth()); //anexa a imagem
-
-
//second modified image
-
mcCamModificado.createEmptyMovieClip('cam2', mcCamModificado.getNextHighestDepth());
-
mcCamModificado.cam2.attachBitmap(imagem, mcCamModificado.getNextHighestDepth()); //anexa a imagem
-
mcCamModificado.cam2._xscale = -100; //inverte a imagem
-
mcCamModificado.cam2._x = mcCamModificado.cam1._x +mcCamModificado.cam1._width + mcCamModificado.cam1._width - 1;
-
-
//the setInterval function executes the updating of the images
-
setInterval(atualizarImagem, 50);
September 22nd, 2007 at 4:58 am
Cool!
May 6th, 2008 at 6:56 pm
www.SillyWebcam.com (play with your web cam online via Flash)