本文整理匯總了Java中java.awt.image.ColorModel.getGreen方法的典型用法代碼示例。如果您正苦於以下問題:Java ColorModel.getGreen方法的具體用法?Java ColorModel.getGreen怎麽用?Java ColorModel.getGreen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.image.ColorModel
的用法示例。
在下文中一共展示了ColorModel.getGreen方法的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);
}
}
}