Login  Register

easy drawing in color images

Posted by leo durosemont on Sep 23, 2005; 10:41am
URL: http://imagej.273.s1.nabble.com/easy-drawing-in-color-images-tp3704798.html

Those of you who (just like me) do not always feel at ease with bit operations, will be able to use this custom setRGBPixel() macro function. It accepts x,y and R,G and B arguments that are converted to a 24 bit word needed by the setPixel(x,y,value) base function to set pixel value in RGB images.
 
Leo.
 
newImage("demo", "RGB", 256, 256, 1);
for (x=0; x<256; x++) {
 for (y=0; y<256; y++) {
  setRGBPixel(x,y,x,y,128);
 }
}
function setRGBPixel (x,y,r,g,b) {
setPixel(x,y,(r&0xff<<16+g&0xff<<8+b&0xff));
}

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com