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:
  1. //importing the classes
  2. import flash.display.*;
  3. import flash.geom.*;
  4.  
  5. //Camera object
  6. var camera:Camera = Camera.get();
  7. //attach the Camera object in video object
  8. mcCam.webcam.attachVideo(camera);
  9.  
  10. //BitmapData object of the final image
  11. var imagem:BitmapData = new BitmapData(camera.width, camera.height, false, 0);
  12. //BitmapData object that will contain the modified image
  13. var imagemContainer:BitmapData = new BitmapData(camera.width, camera.height, false, 0);
  14.  
  15. //rectangle object, it defines the area of the image source in the threshold method
  16. var retangulo = new Rectangle(0, 0, camera.width, camera.height);
  17. //point object, the points correspond to the top-left of the image source in the threshold method
  18. var ponto = new Point(0, 0);
  19.  
  20. //function that will draw the new image
  21. function atualizarImagem():Void{
  22.     //he draws the image of the webcam in the BitmapData object
  23.     imagemContainer.draw(mcCam.webcam);
  24.     //through the threshold method the change of colors is accomplished
  25.     imagem.threshold(imagemContainer, retangulo, ponto, "<", 8000000, 0x006600, 0xFF0000, false);
  26.     imagem.threshold(imagemContainer, retangulo, ponto, ">", 8000000, 0xFF3333, 0xFF0000, false);
  27.     imagem.threshold(imagemContainer, retangulo, ponto, ">", 10000000, 0xFFFF66, 0xFF0000, false);
  28.     imagem.threshold(imagemContainer, retangulo, ponto, ">", 12000000, 0x99FF66, 0xFF0000, false);
  29.     imagem.threshold(imagemContainer, retangulo, ponto, ">", 15000000, 0xFFFFFF, 0xFF0000, false);
  30. };
  31.  
  32. //movieclip to store the modified images
  33. this.createEmptyMovieClip('mcCamModificado', this.getNextHighestDepth());
  34. mcCamModificado._x = 20;
  35. mcCamModificado._y = mcCam._y + mcCam._height + 20;
  36.  
  37. //first modified image
  38. mcCamModificado.createEmptyMovieClip('cam1', mcCamModificado.getNextHighestDepth());
  39. mcCamModificado.cam1.attachBitmap(imagem, mcCamModificado.getNextHighestDepth()); //anexa a imagem
  40.  
  41. //second modified image
  42. mcCamModificado.createEmptyMovieClip('cam2', mcCamModificado.getNextHighestDepth());
  43. mcCamModificado.cam2.attachBitmap(imagem, mcCamModificado.getNextHighestDepth()); //anexa a imagem
  44. mcCamModificado.cam2._xscale = -100; //inverte a imagem
  45. mcCamModificado.cam2._x = mcCamModificado.cam1._x +mcCamModificado.cam1._width + mcCamModificado.cam1._width - 1;
  46.  
  47. //the setInterval function executes the updating of the images
  48. setInterval(atualizarImagem, 50);

4 Responses to “One more experiment, Colored Webcam”

  1. Othon Says:

    Cool!

  2. Gigahertz Inc Says:

    www.SillyWebcam.com (play with your web cam online via Flash)

  3. international no student loans cosigner Says:

    cosigner federal no loans student student loans cosigner no college

  4. injeselossy Says:

    http://hanssenpicky.blogspot.com/2010/03/hanssen-lixiviated-video-robert.html

    free fun videos videos downloads.

Leave a Reply