×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    56

    Gredient ? what is wrong with this method ?

    what is wrong with my code ?
    the result should be a gredient ...

    Code:
            Image buffer = Image.createImage(width, height);
    
            Graphics buufg = buffer.getGraphics();
    
            int[] gredientFrom = {255, 0, 212, 223};
            int[] gredientTo = {255, 99, 20, 14};
    
            int[] gredientDiff = new int[]{
                gredientTo[0] - gredientFrom[0],
                gredientTo[1] - gredientFrom[1],
                gredientTo[2] - gredientFrom[2],
                gredientTo[3] - gredientFrom[3]
            };
    
            int[] buffpx = new int[width * height];
            for (int buffgox = 0; buffgox < width; buffgox++) {
                for (int buffgoy = 0; buffgoy < height; buffgoy++) {
                    buffpx[buffgox + height * buffgoy] =
                            ((gredientFrom[0] + (gredientDiff[0] * buffgox) / width)  & 0xFF << 32) |
                            ((gredientFrom[1] + (gredientDiff[1] * buffgox) / width) & 0xFF<< 16) |
                            ((gredientFrom[2] + (gredientDiff[2] * buffgox) / width) & 0xFF<< 8) |
                            (gredientFrom[3] + (gredientDiff[3] * buffgox) / width);
                }
            }
    
            buufg.drawRGB(buffpx, 0, height, 0, 0, width, height, true);

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Gredient ? what is wrong with this method ?

    Hmmm... would help a little if you told us what kind of gradient (left-to-right, top-to-bottom...?), and what you actually do get...

    It looks to me that:

    buffpx[buffgox + height * buffgoy]
    should read:
    buffpx[buffgox + width * buffgoy]

    Also, bit-shift operators have precedence over bitwise operators, so:
    value & 0xff << 24
    should read:
    (value & 0xff) << 24
    Cheers,
    Graham.

Similar Threads

  1. Replies: 1
    Last Post: 2007-11-23, 10:38
  2. Method Retrive Array
    By Hadad.Net in forum Symbian
    Replies: 8
    Last Post: 2007-08-20, 04:48
  3. what could possibly be wrong?
    By lachee in forum Mobile Java General
    Replies: 6
    Last Post: 2007-07-30, 03:38
  4. Methods, that take lots of space
    By doctordwarf in forum Mobile Java General
    Replies: 4
    Last Post: 2003-07-30, 11:05

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •