How to discolor an ImageIcon image? I hope that there are standard methods.

  • There is a standard method GrayFilter.createDisabledImage(Image i) . It simulates the type of disabled buttons. Off Documentation - LEQADA
  • Interesting, but strangely he makes images, it is not very likely that they are discolored, as if they were grayed out - Denis Kotlyarov
  • Yes, this is not a standard grayscale. It is used to get the disabled button. What do you want? - LEQADA
  • For image discoloration) Any image is given. - Denis Kotlyarov
  • I did not work with images in Java, but the algorithm is approximately the same - you take the color of a dot in RGB and average it. Those. there was for example orange 255, 102, 0. Accordingly, we consider c = (255 + 102 + 0) / 3 = 119. Then we set a new color at this point 119, 119, 119. - Russtam

1 answer 1

You can use ColorConvertOp . He pixel-by-pixel replaces the original image.

 public BufferedImage getGreyScaled(BufferedImage src) { ColorConvertOp colorOp = new ColorConvertOp( ColorSpace.getInstance(ColorSpace.CS_GRAY), null); return colorOp.filter(src, null); } 

enter image description here

Official documentation

To get ImageIcon from BufferedImage use the appropriate ImageIcon(Image image) constructor ImageIcon(Image image)

  • Klastno) works - Denis Kotlyarov