📄 grayscaleimagefilter.java
字号:
import java.awt.*;
import java.awt.image.*;
public class GrayscaleImageFilter extends RGBImageFilter {
public GrayscaleImageFilter() {
canFilterIndexColorModel = true;
}
// Convert color pixels to grayscale
// The algorithm matches the NTSC specification
public int filterRGB(int x, int y, int pixel) {
// Get the average RGB intensity
int red = (pixel & 0x00ff0000) >> 16;
int green = (pixel & 0x0000ff00) >> 8;
int blue = pixel & 0x000000ff;
int luma = (int) (0.299 * red + 0.587 * green + 0.114 * blue);
// Return the luma value as the value for each RGB component
// Note: Alpha (transparency) is always set to max (not transparent)
return (0xff << 24) | (luma << 16) | (luma << 8) | luma;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -