Is this Code Useful for you ?

Is this Posible

Is this Posible
Rack your brain 4 possibilities....

Wednesday, July 28, 2010

gradient

public static void gradient(Graphics g, int color1, int color2, int left, int top, int width, int height, int orientation, int VERTICAL, boolean round) {
int max = orientation == VERTICAL ? height : width;

for (int i = 0; i < max; i++) {
int color = midColor(color1, color2, max * (max - 1 - i) / (max - 1), max);
g.setColor(color);
if (orientation == VERTICAL) {
if (i == 0 && round) {
g.drawLine(left + 3, top + i, left + width - 4, top + i);
} else if (i < 3 && round) {
g.drawLine(left + 1, top + i, left + width - 2, top + i);
} else {
g.drawLine(left, top + i, left + width - 1, top + i);
}

} else {
g.drawLine(left + i, top, left + i, top + height - 1);
}
}
}




public static int midColor(int color1, int color2, int prop, int max) {
int red = (((color1 >> 16) & 0xff) * prop + ((color2 >> 16) & 0xff) * (max - prop)) / max;
int green = (((color1 >> 8) & 0xff) * prop + ((color2 >> 8) & 0xff) * (max - prop)) / max;
int blue = (((color1 >> 0) & 0xff) * prop + ((color2 >> 0) & 0xff) * (max - prop)) / max;
int color = red << 16 | green << 8 | blue;
return color;
}

1 comment:

  1. Hi Mr Gopinath,

    i just wanna ask about the code that u post in the coderanch forum. the code to get rgb and get pixel..
    the code as below:

    # public static int getPixel(Image image, int x, int y) {
    # int[] rgb = new int[image.getWidth() * image.getHeight()];
    # image.getRGB(rgb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
    #
    # int pos = x + (y * image.getWidth());
    # return rgb[pos] << 16 | rgb[pos] << 8 | rgb[pos];
    #
    # }
    #
    # public static int getRGBPixel(Image image, int ps) {
    # int[] rgb = new int[image.getWidth() * image.getHeight()];
    # image.getRGB(rgb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
    #
    #
    # return rgb[ps];


    from that code. i dont understand what 'pos' meant? and what is ps actually?

    im sorry if i ask such a stupid question. because of these two, i dont understand the code. thank you...

    ReplyDelete