📄 thresholdingfilter.java
字号:
package image.filter;
import image.EditableImage;
import image.ImagingUtils;
public class ThresholdingFilter extends AbstractFilter {
public ThresholdingFilter(EditableImage image) {
super(image);
}
public void processFilter() {
int threshold = ((Integer)getParameter("threshold")).intValue();
if (threshold > 0 && threshold <= 255) {
int width = image.getWidth();
int height = image.getHeight();
for (int h = 0; h < height; h++) {
for (int w = 0; w < width; w++) {
image.getImage().setRGB(w, h, thresholdPixel(image.getImage().getRGB(w, h), threshold));
}
}
}
}
private int thresholdPixel(int pixel, int threshold) {
return ImagingUtils.convertPixel((((ImagingUtils.convertToGrayscale(pixel) & 0x00FF0000) >>> 16) > threshold) ? 255 : 0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -