function rgbToMatrix ( r, g, b, a ) 
{
    var matrix:Array = new Array();
    matrix = matrix.concat([r, 0, 0, 0, 0]); // red
    matrix = matrix.concat([0, g, 0, 0, 0]); // green
    matrix = matrix.concat([0, 0, b, 0, 0]); // blue
    matrix = matrix.concat([0, 0, 0, a, 0]); // alpha
    return matrix;
}
var matrix = rgbToMatrix ( 1, 1, 0, 100 );
var filter = new flash.filters.ColorMatrixFilter ( matrix );
mc.filters = [ filter ];


or


function hexToMatrix ( hex, alpha ) 
{
    var matrix:Array = [];
    matrix = matrix.concat([((hex & 0x00FF0000) >>> 16)/255, 0, 0, 0, 0]);
// red
    matrix = matrix.concat([0, ((hex & 0x0000FF00) >>> 8)/255, 0, 0, 0]); //
green
    matrix = matrix.concat([0, 0, (hex & 0x000000FF)/255, 0, 0]); // blue
    matrix = matrix.concat([0, 0, 0, alpha/100, 0]); // alpha
    return matrix;
}
var matrix = hexToMatrix ( 0x44DAFF, 100 );
var filter = new flash.filters.ColorMatrixFilter ( matrix );
mc.filters = [ filter ];        




_____________________________

Jesse Graupmann
www.jessegraupmann.com   
www.justgooddesign.com/blog/     
_____________________________



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mike
Mountain
Sent: Thursday, May 10, 2007 2:40 AM
To: flashcoders@chattyfig.figleaf.com
Subject: Re: [Flashcoders] RGB tinting using the colorMatrixFilter()

not sure I made myself clear - given a desaturated greyscale image I need to
be able to tint it to an RGB value - so black stays black, white stays white
and rgb=128,128,228 (50% grey) is the actual colour - with all the shade in
between. I need to be able to do this by using code like this:

[as3]
    trace("composite startTime:"+getTimer());
    // tint
    var matrix:Array = new Array();
    matrix = matrix.concat([r1, r2, r3, r4, r5]);
    matrix = matrix.concat([g1, g2, g3, g4, g5]);
    matrix = matrix.concat([b1, b2, b3, b4, b5]);
    matrix = matrix.concat([a1, a2,a3, a4, a5]);
    var tintFilter = new ColorMatrixFilter(matrix);
[/as3]

so how do I work out the r's g's and b's in the matrix?

Cheers

Mike

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to