當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。