本文整理汇总了Java中java.awt.image.ColorModel.getRed方法的典型用法代码示例。如果您正苦于以下问题:Java ColorModel.getRed方法的具体用法?Java ColorModel.getRed怎么用?Java ColorModel.getRed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.ColorModel
的用法示例。
在下文中一共展示了ColorModel.getRed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderChar
import java.awt.image.ColorModel; //导入方法依赖的package包/类
public void renderChar(FontMetrics fontMetrics, BufferedImage image, char c, int safetyMargin) {
double[][] red = new double[image.getWidth()][image.getHeight()];
double[][] green = new double[image.getWidth()][image.getHeight()];
double[][] blue = new double[image.getWidth()][image.getHeight()];
double[][] alpha = new double[image.getWidth()][image.getHeight()];
ColorModel cm = image.getColorModel();
for(int x=kernel.getWidth()/2; x < image.getWidth()-kernel.getWidth()/2; x++) {
for(int y=kernel.getHeight()/2; y < image.getHeight()-kernel.getHeight()/2; y++) {
for(int j=0 ; j<kernel.getWidth(); j++) {
for(int k=0; k<kernel.getHeight(); k++) {
int rgb = image.getRGB(
x+j-kernel.getWidth()/2,
y+k-kernel.getHeight()/2);
double value = kernel.getValue(j, k);
red[x][y] += cm.getRed(rgb)*value;
green[x][y] += cm.getGreen(rgb)*value;
blue[x][y] += cm.getBlue(rgb)*value;
alpha[x][y] += cm.getAlpha(rgb)*value;
}
}
}
}
if(normalize) {
normalize(red, green, blue, alpha);
}
Graphics2D g = image.createGraphics();
Clear.clear(g, image.getWidth(), image.getHeight());
for(int x=0; x < image.getWidth(); x++) {
for(int y=0; y < image.getHeight(); y++) {
if(red[x][y] > 255) red[x][y] = 255;
if(green[x][y] > 255) green[x][y] = 255;
if(blue[x][y] > 255) blue[x][y] = 255;
if(alpha[x][y] > 255) alpha[x][y] = 255;
if(red[x][y] < 0) red[x][y] = 0;
if(green[x][y] < 0) green[x][y] = 0;
if(blue[x][y] < 0) blue[x][y] = 0;
if(alpha[x][y] < 0) alpha[x][y] = 0;
// @todo optimize drawing the image with image.setRGB #
Color color = new Color((int)red[x][y], (int)green[x][y], (int)blue[x][y], (int)alpha[x][y]);
g.setColor(color);
g.drawLine(x, y, x, y);
}
}
}