PROBLEM

Converting an image to a grayscale format without creating another image file. (For actionscript)

SOLUTION
Use the function below and pass an image object to be converted:


private function convertToGrayscale(image:DisplayObject):void 
{ 
  var matrix:Array = [0.3, 0.59, 0.11, 0, 0, 
              0.3, 0.59, 0.11, 0, 0, 
              0.3, 0.59, 0.11, 0, 0, 
              0, 0, 0, 1, 0]; 
               
  var grayscaleFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix); 
  var filters:Array = image.filters; 
  filters.push(grayscaleFilter); 
  image.filters = filters; 
  
} 


No comments :

Post a Comment