all groups > flash actionscript > october 2006 >
You're in the

flash actionscript

group:

pixel manipulation


pixel manipulation stephan.k
10/28/2006 11:02:38 PM
flash actionscript: Dear Forum

I'm looking for a way to get rgb values (Hex) of pixels in a bitmapData
rounded to the next closest websafe color.

Any ideas? Is this already built in flash? are there any Algortithms out
there?

thanks

stephan


Re: pixel manipulation kglad
10/29/2006 12:55:21 AM
pass your bmp to webSafeBMPF and it will color it websafe:





function webSafeBMPF(bmp) {
for (var x = 1; x<=Math.round(bmp.width); x++) {
for (var y = 1; y<=Math.round(bmp.height); y++) {
bmp.setPixel(x, y, "0x"+webSafeColorF(bmp.getPixel(x, y)));
}
}
}
function webSafeColorF(col) {
newCol = "";
for (var j = 2; j>=0; j--) {
tempCol = (col >> (j*8) & 0xFF);
if (tempCol%51<25) {
tempCol = tempCol-tempCol%51;
} else {
tempCol = tempCol+(51-tempCol%51);
}
while (tempCol.toString(16).length != 2) {
tempCol = "0"+tempCol;
}
newCol += tempCol.toString(16);
}
return newCol;
}
Re: pixel manipulation NSurveyor
10/29/2006 1:28:29 AM
Here's how I would do it... you would use something like myBitmap.webSafe();

import flash.display.BitmapData;
import flash.geom.Point;
BitmapData.prototype.webSafe = function() {
var r:Array = new Array(256);
var g:Array = new Array(256);
var b:Array = new Array(256);
for (var i = 0; i<=255; i++) {
var v = Math.round(i/51)*51;
r[i] = v << 16;
g[i] = v << 8;
b[i] = v << 0;
}
this.paletteMap(this, this.rectangle, new Point(0, 0), r, g, b, null);
};
Re: pixel manipulation stephan.k
11/2/2006 12:44:09 AM
excellent! thanks guys...
Re: pixel manipulation kglad
11/2/2006 4:46:45 AM
AddThis Social Bookmark Button