A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Get the color of a pixel at x&y

  1. #1
    Member
    Join Date
    Sep 2008
    Posts
    36

    Post Get the color of a pixel at x&y

    I made a little test to do this. But, it doens't work. ]=
    Lets say i drew this blue square, 50px * 50px.
    It is not a movieclip.
    Now I want to know what color is at the center of the square:

    Code:
    import flash.display.BitmapData;
    var kl:BitmapData = new BitmapData (50, 50);
    trace (kl.getPixel (25, 25).toString(16));
    The problem is, whatever color i give the square, it keeps tracing "ffffff".
    getRGB and setRGB is no option. I tried that and it works in this case, but i cant use it in this case.

  2. #2
    Member
    Join Date
    Oct 2006
    Location
    Belgium
    Posts
    36
    Hi fjodorvanveen,

    Try this one:

    PHP Code:
    import flash.display.BitmapData;

    var 
    bitmap_1:BitmapData = new BitmapData (5050false0x0000FF);

    trace (bitmap_1.width); // 50
    trace (bitmap_1.height); // 50
    trace (bitmap_1.transparent); // false
    trace (bitmap_1.getPixel (2525).toString(16)); // ff

    this.attachBitmap(bitmap_1this.getNextHighestDepth()); 
    For more information go to http://livedocs.adobe.com/flash/8/ma...=00001942.html

  3. #3
    Member
    Join Date
    Sep 2008
    Posts
    36
    Ty a lot!
    This helps me out I guess.

  4. #4
    Member
    Join Date
    Sep 2008
    Posts
    36
    Allright, one final question. I can get the RGB of a script generated bitmap with a solid colour.
    So now I got this code wich generates a radial circle with 3 random colors.

    PHP Code:
    this.createEmptyMovieClip ("gradient_mc",_root.getNextHighestDepth());
    with (gradient_mc) {
        
    _x 300;
        
    _y 300;
        
    beginGradientFill ("radial",[Math.random () * 0xFFFFFFMath.random () * 0xFFFFFFMath.random () * 0xFFFFFF],[100100100],[0125255],{matrixType:"box"x:-100y:-100w:200h:200r:0});
        
    moveTo (100,0);
        for (var 
    a:Number 0<= 360a++) {
            
    lineTo (100 Math.cos (57.2),100 Math.sin (57.2));
        }
        
    endFill ();

    I know I have to create a bitmapData, but I cant firgure out how to put that movieclip into that bitmapdata and stuff.

    How do I get the RGB at the xmouse and ymouse position?

  5. #5
    Member
    Join Date
    Oct 2006
    Location
    Belgium
    Posts
    36
    PHP Code:
    import flash.display.BitmapData;

    function 
    Make (XYWH)
    {
       
    _root.createEmptyMovieClip ("gradient_mc",_root.getNextHighestDepth ());

       
    with (_root.gradient_mc)
       {
          
    _x X;
          
    _y Y
          
          
    var fillType:String "radial";
          var 
    Colors:Array = [Math.random () * 0xFFFFFFMath.random () * 0xFFFFFFMath.random () * 0xFFFFFF];
          var 
    alphas:Array = [100100100];
          var 
    ratios:Array = [0125255];

          
    beginGradientFill (fillTypeColorsalphasratios, {matrixType:"box"x:0y:0w:Wh:Hr:0});

          
    moveTo (W,2);

          for (var 
    a:Number 0<= 360a++)
          {
             
    lineTo (Math.cos (57.2) + (2),Math.sin (57.2) + (2));
          }
          
          
    endFill ();
       }
       
       
    MyBitmapData = new BitmapData (WHtrue);
       
    MyBitmapData.draw (_root.gradient_mc);
       
       
    _root.gradient_mc.onPress = function ()
       {
          var 
    MyMouseX:Number =  _root.gradient_mc._xmouse;
          var 
    MyMouseY:Number =  _root.gradient_mc._ymouse;
          
    trace (MyBitmapData.getPixel (MyMouseXMyMouseY).toString (16));
       };
    }

    Make (00200200); 

  6. #6
    Member
    Join Date
    Sep 2008
    Posts
    36
    Thats exactly what I need, Thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center