[Bluej-discuss] exercise 11.37 page 331

Luis Moreira luis.moreira at hotmail.co.uk
Mon May 8 17:51:58 BST 2006


Hi Michael,
this is what I have done, based on what I got from your email, but the 
problem is that all pixels go blue. Is this what you mean or am I missing 
something?

public void apply(OFImage image)
    {
        int height = image.getHeight();
        int width = image.getWidth();
        for(int y = 0; y < height; y++) {
            for(int x = 0; x < width; x++) {
                Color pixel = image.getPixel(x, y);
                int red = pixel.getRed();
                int green = pixel.getGreen();
                int blue = pixel.getBlue();
                int value = (red + green + blue)/ 3;
                image.setPixel(x, y, value);
            }
        }
    }


>From: Michael Kölling <M.Kolling at kent.ac.uk>
>Reply-To: General discussion for users of BlueJ <bluej-discuss at bluej.org>
>To: General discussion for users of BlueJ <bluej-discuss at bluej.org>
>Subject: Re: [Bluej-discuss] exercise 11.37 page 331
>Date: Mon, 8 May 2006 16:17:20 +0100
>
>On 8 May 2006, at 16:12, Luis Moreira wrote:
>
> > Hi Guys,
> > on exercise 11.37, I manage to add the filter no problem, but the
> > functionality I could not work out.
> > the exercise states that to make a pixel any shade of gray we give
> > the same
> > value to red,green and blue. that is fine but what value do I need
> > to give
> > the three components?
>
>You can preserve the brightness (roughly) by leaving the sum of the R/
>G/B channels the same.
>
>That is, compute the average of the R, G and B values, and use that
>average for all three channels.
>
>Regards,
>
>Michael
>
>_______________________________________________
>mailing list bluej-discuss at bluej.org
>To unsubscribe or change your preferences, go to
>http://lists.bluej.org/mailman/listinfo/bluej-discuss

_________________________________________________________________
The new MSN Search Toolbar now includes Desktop search! 
http://join.msn.com/toolbar/overview



More information about the bluej-discuss mailing list