×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    6

    Unhappy Gradient Fill Banding Problems

    I've created a method that returns an image containing a gradient fill. I create an RGB array and smoothly change between the 2 colours. I then return the image created using Image.createRGBImage.

    When i run the app on the device (6630) quite a lot of banding between the colours is visible.

    I tried exactly the same gradient fill on an image and there was no banding so i know its possible to have a smooth transition.

    I have tried taking the RGB data and creating a PNG manually (using CRC and Adler checksums etc) then loading that in as a byte[] which also works fine (but is more expensive and complex than the createRGBImage).

    I have tried taking an image with the gradient fill on, getting the RGB data from it and then recreating the image again with createRGBImage and that works fine.

    The device must therefore convert the RGB values when reading in a PNG into a screen friendly format but i've no idea how it does this. Can anybody shed some light on this for me?

    And yes I know the device format is 5:6:5 RGB but looking at the values from getRGB it hasn't converted them into that.

  2. #2
    Regular Contributor
    Join Date
    Jan 2004
    Posts
    82

    Re: Gradient Fill Banding Problems

    Quote Originally Posted by benc_1
    The device must therefore convert the RGB values when reading in a PNG into a screen friendly format but i've no idea how it does this. Can anybody shed some light on this for me?
    Everytime you open a image with Image.createImage(..) The image is decoded and stored in a "screen friendly" format (as some kind of bitmap).


    Quote Originally Posted by benc_1
    And yes I know the device format is 5:6:5 RGB but looking at the values from getRGB it hasn't converted them into that.
    The getRGB() method returns an integer array with one integer = one pixel, see javadoc of getRGB() for the next (and even more):
    Obtains ARGB pixel data from the specified region of this image and stores it in the provided array of integers. Each pixel value is stored in 0xAARRGGBB format, where the high-order byte contains the alpha channel and the remaining bytes contain color components for red, green and blue, respectively.
    The returned values are not guaranteed to be identical to values from the original source, such as from createRGBImage or from a PNG image. Color values may be resampled to reflect the display capabilities of the device...
    I've written a method a while ago that creates an "gradient-array" You could try it...
    It returns an array that starts with aStartColor and turns smoothly into aEndcolor. aLength determines the length of the array(gradient).
    Code:
    public int[] getGradient(int aStartColor, int aEndColor, int aLength){
    		
    		int r1 = aStartColor>>16;		
    		int g1 = aStartColor>>8;
    		g1 = g1 & 0x0000FF;
    		int b1 = aStartColor;
    		b1 = b1 & 0x0000FF;
    		
    		
    		int r2 = aEndColor>>16;		
    		int g2 = aEndColor>>8;
    		g2 = g2 & 0x0000FF;
    		int b2 = aEndColor;
    		b2 = b2 & 0x0000FF;
    		
    		int res_r = 0;
    		int res_g = 0;
    		int res_b = 0;
    		
    		int gradient[] = new int[aLength];
    		
    		int counter = 0;
    		int dif;
    		while(counter < aLength){
    			dif = (aLength-counter);
    			res_r =  (r1 * dif + r2*counter)/aLength ;
    			res_g =  (g1 * dif + g2*counter)/aLength ;
    			res_b =  (b1 * dif + b2*counter)/aLength ;	
    			
    			res_r = res_r <<16;
    			res_g = res_g <<8;
    			
    			gradient[counter] = (res_r | res_g | res_b);
    			         
    			counter++;
    		}		
    		return gradient;
    	}

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    6

    Re: Gradient Fill Banding Problems

    Thanks for your help, i hadn't seen the text in the getRGB definition.

    Tried your gradient code, unfortunately banding still occurs, thanks for the suggestion though.

Similar Threads

  1. Usability problems still need fixing. Can we help nokia?
    By Trial in forum General Development Questions
    Replies: 3
    Last Post: 2004-02-26, 15:05
  2. Problems with Nokia carkit CK-1W
    By Batunas in forum General Development Questions
    Replies: 1
    Last Post: 2004-02-09, 18:18
  3. Problems installing Nokia developers suite with JBuilder 8 Personal
    By maaberge in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2003-04-05, 00:42
  4. Doing a gradient fill
    By nkn_aikon in forum Symbian User Interface
    Replies: 1
    Last Post: 2001-11-28, 21:23
  5. Doing a gradient fill
    By nkn_aikon in forum Symbian
    Replies: 1
    Last Post: 2001-11-08, 18:48

Posting Permissions

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