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)!!
Please sign in to leave a comment.
here's a example picture!!!
Attachment(s):
example.jpeg
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:
Nathan Brown wrote:
...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/
DisclaimerThis 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.
thats good, but the background of the icon is white. here my example code. i have a blackWhite filter, too:
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
that's it. THANKS!!!!!
:) 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:
>> 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...
>
>
Attachment(s):
grayed.JPG
>
>+ (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... > >
>
>
>
>+ (0.072169F * c.getBlue()));
>}
></pre>
>
>Michael Seele wrote:
>> here's a example picture!!!
>
i've wrote a colorFilter that change the icon to the given color, but always the color of the icon is red. why??? code:
that change * the image to the desired color. * */ public class ColorFilter extends RGBImageFilter { /** * The to which the image should changed. * */ private Color color; /** * Creates a new that change the * image to the c. * * @param c the 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)); } } ]]>