Posted By

IsoJon on 07/03/10


Tagged

bitmapData


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Vordreller
shalomfriss
PixelJuice


Get Color Array of handdrawn Gradient


 / Published in: ActionScript 3
 

I created this snippet as a small utility to populate Michael Vandaniker's Heat Map application with it's necessary gradient information.

It makes it possible to extract a color array for every pixel of a hand drawn gradient (giving you tons of control over the color and style of the gradient). Check out Michael's Heat Map application here: http://michaelvandaniker.com/blog/2008/07/06/how-to-make-heat-maps-in-flex/

I think this could have numerous other applications. Make something cool.

  1. import flash.display.BitmapData;
  2. import flash.display.Bitmap;
  3.  
  4. // Edit your gradient by hand in the library instance, publish to copy the array for the gradient dictionary.
  5.  
  6. //** ColorMC is the linkage ID of my bitmap in the library
  7.  
  8. // this is the height & width of your bitmap
  9. var bitWidth:Number = 255;
  10. var bitHeight:Number = 10;
  11. var bitArray:Array = new Array();
  12.  
  13. var colorMC:MovieClip = new ColorMC();
  14. var myBitmapData:BitmapData = new BitmapData(bitWidth, bitHeight);
  15. myBitmapData.draw(colorMC);
  16. var bmp:Bitmap = new Bitmap(myBitmapData);
  17. addChild(bmp);
  18.  
  19. for (var i = 0; i < bitWidth; i++)
  20. {
  21. bitArray.push(myBitmapData.getPixel32(i, 1));
  22.  
  23. if ( bitArray.length == 254 )
  24. {
  25. trace( bitArray );
  26. }
  27. }

Report this snippet  

You need to login to post a comment.