paint icon grey

hi,
sorry, this question has nothing to do with the eap but rather with java. please help me anyway!!!
how can i paint a icon/image grey like the intelliJ guys make this with the disabled tool windows(shown on the example picture)!!

8 comments

here's a example picture!!!



Attachment(s):
example.jpeg
0

Can't see an example picture here, so I'm just going to guess.

heres a java class that will greyscale an image for you...

]]>
public class GreyScaleFilter extends RGBImageFilter
{
/**

  • Creates a disabled image

*/
public static Image createGreyScaleImage(Image i)
{
GreyScaleFilter filter = new GreyScaleFilter();
ImageProducer prod = new FilteredImageSource(i.getSource(), filter);
Image rolloverImage = Toolkit.getDefaultToolkit().createImage(prod);
return rolloverImage;
}

public GreyScaleFilter()
{
super();
canFilterIndexColorModel = true;
}

public int filterRGB(int x, int y, int rgb)
{
int brightness = getBrightness(rgb);
return new Color(brightness, brightness, brightness).getRGB();
}

public static int getBrightness(int rgb)
{
Color c = new Color(rgb);
return Math.round((0.212671F * c.getRed()) + (0.715160F * c.getGreen())
+ (0.072169F * c.getBlue()));
}
}
</pre>

Michael Seele wrote:

here's a example picture!!!



0

Nathan Brown wrote:

Can't see an example picture here, so I'm just going to guess.

heres a java class that will greyscale an image for you...


...or you could just use javax.swing.GrayFilter, which does exactly the same
thing and has been part of the JDK since 1.3.1, if not earlier. :)

Vil.
--
Vilya Harvey, Consultant
vilya.harvey@digitalsteps.com / digital steps /
(W) +44 (0)1483 469 480
(M) +44 (0)7816 678 457 http://www.digitalsteps.com/

Disclaimer

This e-mail and any attachments may be confidential and/or legally
privileged. If you have received this email and you are not a named
addressee, please inform the sender at Digital Steps Ltd by phone on
+44 (0)1483 469 480 or by reply email and then delete the email from
your system. If you are not a named addressee you must not use,
disclose, distribute, copy, print or rely on this email. Although
Digital Steps Ltd routinely screens for viruses, addressees should
check this email and any attachments for viruses. Digital Steps Ltd
makes no representation or warranty as to the absence of viruses in this
email or any attachments.


0

thats good, but the background of the icon is white. here my example code. i have a blackWhite filter, too:

> 24) & 0xff;
		int red = (int) (((rgb >> 16) & 0xff) * 0.3f);
		int green = (int) (((rgb >> 8) & 0xff) * 0.59f);
		int blue = (int) ((rgb & 0xff) * 0.11f);
		int bws = ((red + green + blue) > 127) ? 255 : 0;
		return ((alpha & 0xFF) << 24) | ((bws & 0xFF) << 16) | ((bws & 0xFF) << 8) | ((bws & 0xFF) << 0);
	}

}]]>


here are a example from IDEA. there are the disabled tool buttons grey and when the tool button is enabled it's colored.



Attachment(s):
example.jpeg
0

:) GrayFilter does not do exactly the same thing, I've attached a
screenshot to show the difference... as I was guessing to what he wanted (no
screenshot) I thought he might be after something other than the basic swing
functionality.

Vilya Harvey wrote:

Nathan Brown wrote:

>> Can't see an example picture here, so I'm just going to guess.
>>
>> heres a java class that will greyscale an image for you...
>

...or you could just use javax.swing.GrayFilter, which does exactly
the same thing and has been part of the JDK since 1.3.1, if not
earlier. :)

>

Vil.






Attachment(s):
grayed.JPG
0

public int filterRGB(int x, int y, int rgb)
{
int brightness = getBrightness(rgb);
return new Color(brightness, brightness, brightness).getRGB();
}

>

public static int getBrightness(int rgb)
{
Color c = new Color(rgb);
return Math.round((0.212671F * c.getRed()) + (0.715160F * c.getGreen())

>+ (0.072169F * c.getBlue()));

Do you really create two new Colors for each pixel or map-entry?

Tom


"Nathan Brown" schrieb: >Can't see an example picture here, so I'm just going to guess. > >heres a java class that will greyscale an image for you... > >

>public class GreyScaleFilter extends RGBImageFilter
>]]>
{

/**

  • Creates a disabled image

*/
public static Image createGreyScaleImage(Image i)
{
GreyScaleFilter filter = new GreyScaleFilter();
ImageProducer prod = new FilteredImageSource(i.getSource(), filter);
Image rolloverImage = Toolkit.getDefaultToolkit().createImage(prod);
return rolloverImage;
}

>

public GreyScaleFilter()
{
super();
canFilterIndexColorModel = true;
}

>

public int filterRGB(int x, int y, int rgb)
{
int brightness = getBrightness(rgb);
return new Color(brightness, brightness, brightness).getRGB();
}

>

public static int getBrightness(int rgb)
{
Color c = new Color(rgb);
return Math.round((0.212671F * c.getRed()) + (0.715160F * c.getGreen())

>+ (0.072169F * c.getBlue()));

}

>}
></pre>
>
>Michael Seele wrote:
>> here's a example picture!!!
>

0

i've wrote a colorFilter that change the icon to the given color, but always the color of the icon is red. why??? code:

RGBImageFilter
that change * the image to the desired color. * */ public class ColorFilter extends RGBImageFilter { /** * The
Color
to which the image should changed. * */ private Color color; /** * Creates a new
ColorFilter
that change the * image to the
Color
c. * * @param c the
Color
to which * the image should be changed * */ public ColorFilter(Color c) { color = c; canFilterIndexColorModel = true; } public int filterRGB(int x, int y, int rgb) { //detect the transparency of the pixel int alpha = (rgb >> 24) & 0xff; //if the pixel is fully transparent make nothing if (alpha == 0) { return rgb; } float[] hsb = Color.RGBtoHSB((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff, null); //change the pixel to the new color hsb[0] = Math.round((0.212671F * color.getRed()) + (0.715160F * color.getGreen()) + (0.072169F * color.getBlue())); //add the transparency of the pixel and return it return (Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]) + (alpha << 24)); } } ]]>

0

Please sign in to leave a comment.