-
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.
-
Hi fjodorvanveen,
Try this one:
PHP Code:
import flash.display.BitmapData;
var bitmap_1:BitmapData = new BitmapData (50, 50, false, 0x0000FF);
trace (bitmap_1.width); // 50 trace (bitmap_1.height); // 50 trace (bitmap_1.transparent); // false trace (bitmap_1.getPixel (25, 25).toString(16)); // ff
this.attachBitmap(bitmap_1, this.getNextHighestDepth());
For more information go to http://livedocs.adobe.com/flash/8/ma...=00001942.html
-
Ty a lot!
This helps me out I guess.
-
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 () * 0xFFFFFF, Math.random () * 0xFFFFFF, Math.random () * 0xFFFFFF],[100, 100, 100],[0, 125, 255],{matrixType:"box", x:-100, y:-100, w:200, h:200, r:0}); moveTo (100,0); for (var a:Number = 0; a <= 360; a++) { lineTo (100 * Math.cos (a / 57.2),100 * Math.sin (a / 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?
-
PHP Code:
import flash.display.BitmapData;
function Make (X, Y, W, H)
{
_root.createEmptyMovieClip ("gradient_mc",_root.getNextHighestDepth ());
with (_root.gradient_mc)
{
_x = X;
_y = Y
var fillType:String = "radial";
var Colors:Array = [Math.random () * 0xFFFFFF, Math.random () * 0xFFFFFF, Math.random () * 0xFFFFFF];
var alphas:Array = [100, 100, 100];
var ratios:Array = [0, 125, 255];
beginGradientFill (fillType, Colors, alphas, ratios, {matrixType:"box", x:0, y:0, w:W, h:H, r:0});
moveTo (W,H / 2);
for (var a:Number = 0; a <= 360; a++)
{
lineTo (W / 2 * Math.cos (a / 57.2) + (W / 2),H / 2 * Math.sin (a / 57.2) + (H / 2));
}
endFill ();
}
MyBitmapData = new BitmapData (W, H, true);
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 (MyMouseX, MyMouseY).toString (16));
};
}
Make (0, 0, 200, 200);
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|