当前位置: 首页>>代码示例>>Java>>正文


Java ColorModel.getAlpha方法代码示例

本文整理汇总了Java中java.awt.image.ColorModel.getAlpha方法的典型用法代码示例。如果您正苦于以下问题:Java ColorModel.getAlpha方法的具体用法?Java ColorModel.getAlpha怎么用?Java ColorModel.getAlpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.image.ColorModel的用法示例。


在下文中一共展示了ColorModel.getAlpha方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compare

import java.awt.image.ColorModel; //导入方法依赖的package包/类
private boolean compare(BufferedImage in, BufferedImage out) {
    int width = in.getWidth();
    int height = in.getHeight();
    if (out.getWidth() != width || out.getHeight() != height) {
        throw new RuntimeException("Dimensions changed!");
    }

    Raster oldras = in.getRaster();
    ColorModel oldcm = in.getColorModel();
    Raster newras = out.getRaster();
    ColorModel newcm = out.getColorModel();

    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            Object oldpixel = oldras.getDataElements(i, j, null);
            int oldrgb = oldcm.getRGB(oldpixel);
            int oldalpha = oldcm.getAlpha(oldpixel);

            Object newpixel = newras.getDataElements(i, j, null);
            int newrgb = newcm.getRGB(newpixel);
            int newalpha = newcm.getAlpha(newpixel);

            if (newrgb != oldrgb ||
                newalpha != oldalpha) {
                throw new RuntimeException("Pixels differ at " + i +
                                           ", " + j);
            }
        }
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:WBMPPluginTest.java

示例2: compare

import java.awt.image.ColorModel; //导入方法依赖的package包/类
private boolean compare(final BufferedImage in, final BufferedImage out) {

            final int width = in.getWidth();
            int height = in.getHeight();
            if (out.getWidth() != width || out.getHeight() != height) {
                throw new RuntimeException("Dimensions changed!");
            }

            Raster oldras = in.getRaster();
            ColorModel oldcm = in.getColorModel();
            Raster newras = out.getRaster();
            ColorModel newcm = out.getColorModel();

            for (int j = 0; j < height; j++) {
                for (int i = 0; i < width; i++) {
                    Object oldpixel = oldras.getDataElements(i, j, null);
                    int oldrgb = oldcm.getRGB(oldpixel);
                    int oldalpha = oldcm.getAlpha(oldpixel);

                    Object newpixel = newras.getDataElements(i, j, null);
                    int newrgb = newcm.getRGB(newpixel);
                    int newalpha = newcm.getAlpha(newpixel);

                    if (newrgb != oldrgb ||
                        newalpha != oldalpha) {
                        // showDiff(in, out);
                        throw new RuntimeException("Pixels differ at " + i +
                                                   ", " + j + " new = " + Integer.toHexString(newrgb) + " old = " + Integer.toHexString(oldrgb));
                    }
                }
            }
            return true;
        }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:BMPCompressionTest.java

示例3: compare

import java.awt.image.ColorModel; //导入方法依赖的package包/类
private static boolean compare(final BufferedImage in,
                               final BufferedImage out)
{
    final int width = in.getWidth();
    int height = in.getHeight();
    if (out.getWidth() != width || out.getHeight() != height) {
        throw new RuntimeException("Dimensions changed!");
    }

    Raster oldras = in.getRaster();
    ColorModel oldcm = in.getColorModel();
    Raster newras = out.getRaster();
    ColorModel newcm = out.getColorModel();

    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            Object oldpixel = oldras.getDataElements(i, j, null);
            int oldrgb = oldcm.getRGB(oldpixel);
            int oldalpha = oldcm.getAlpha(oldpixel);

            Object newpixel = newras.getDataElements(i, j, null);
            int newrgb = newcm.getRGB(newpixel);
            int newalpha = newcm.getAlpha(newpixel);

            if (newrgb != oldrgb ||
                newalpha != oldalpha) {
                // showDiff(in, out);
                throw new RuntimeException("Pixels differ at " + i +
                                           ", " + j + " new = " + Integer.toHexString(newrgb) + " old = " + Integer.toHexString(oldrgb));
            }
        }
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:BMPWriteParamTest.java

示例4: compare

import java.awt.image.ColorModel; //导入方法依赖的package包/类
public static void compare(BufferedImage oldimg,
                           BufferedImage newimg) {
    int width = oldimg.getWidth();
    int height = oldimg.getHeight();
    if (newimg.getWidth() != width || newimg.getHeight() != height) {
        throw new RuntimeException("Dimensions changed!");
    }

    Raster oldras = oldimg.getRaster();
    ColorModel oldcm = oldimg.getColorModel();
    Raster newras = newimg.getRaster();
    ColorModel newcm = newimg.getColorModel();

    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            Object oldpixel = oldras.getDataElements(i, j, null);
            int oldrgb = oldcm.getRGB(oldpixel);
            int oldalpha = oldcm.getAlpha(oldpixel);

            Object newpixel = newras.getDataElements(i, j, null);
            int newrgb = newcm.getRGB(newpixel);
            int newalpha = newcm.getAlpha(newpixel);

            if (newrgb != oldrgb ||
                newalpha != oldalpha) {
                throw new RuntimeException("Pixels differ at " + i +
                                           ", " + j);
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:ImageCompare.java

示例5: 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);
		}
	}
	
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:58,代码来源:Convolution.java

示例6: cropImage

import java.awt.image.ColorModel; //导入方法依赖的package包/类
private BufferedImage cropImage(BufferedImage bi, char c) 
{
	ColorModel cm = bi.getColorModel();

	int startX = 0;
	int endX = fontMetrics.charWidth(c);

	// coming from the right, going to the left
	for (int x = fontMetrics.charWidth(c); x < bi.getWidth(); x++) 
	{
		boolean hasAlpha = false;
		
		for (int y = 0; y < bi.getHeight(); y++) 
		{
			if (cm.getAlpha(bi.getRGB(x, y)) != 0) 
			{
				hasAlpha = true;
				endX = x+1;
				break;
			}
		}
		
		if(!hasAlpha) break;
	}
	
	//System.out.println(c+" StartX: "+startX+", endX: "+endX);
	/*
	if(c == ' ')
	{
		endX = fontMetrics.charWidth(' ');
		startX = 0;
	}
	*/

	//endX++;
	//endX++;
	
	// large fonts need extra space
	//while(endX - startX < fontMetrics.charWidth(c)) endX++;
	
	BufferedImage cropped = new BufferedImage(endX - startX, fontMetrics.getMaxAscent()+fontMetrics.getMaxDescent(),
			bi.getType());
	cropped.getGraphics().drawImage(bi, -startX, 0, null);

	return cropped;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:47,代码来源:FontFactory.java


注:本文中的java.awt.image.ColorModel.getAlpha方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。