當前位置: 首頁>>代碼示例>>Java>>正文


Java ImageFilter類代碼示例

本文整理匯總了Java中java.awt.image.ImageFilter的典型用法代碼示例。如果您正苦於以下問題:Java ImageFilter類的具體用法?Java ImageFilter怎麽用?Java ImageFilter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ImageFilter類屬於java.awt.image包,在下文中一共展示了ImageFilter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applyAlphaChannel

import java.awt.image.ImageFilter; //導入依賴的package包/類
/**
 * All pixels that have the specified color are rendered transparent.
 *
 * @param img
 *          the img
 * @param color
 *          the color
 * @return the image
 */
public static Image applyAlphaChannel(final Image img, final Color color) {
  if (color == null || img == null) {
    return img;
  }

  final ImageFilter filter = new RGBImageFilter() {

    // the color we are looking for... Alpha bits are set to opaque
    public final int markerRGB = color.getRGB() | 0xFF000000;

    @Override
    public final int filterRGB(final int x, final int y, final int rgb) {
      if ((rgb | 0xFF000000) == this.markerRGB) {
        // Mark the alpha bits as zero - transparent
        return 0x00FFFFFF & rgb;
      } else {
        // nothing to do
        return rgb;
      }
    }
  };

  final ImageProducer ip = new FilteredImageSource(img.getSource(), filter);
  return Toolkit.getDefaultToolkit().createImage(ip);
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:35,代碼來源:ImageProcessing.java

示例2: getGrayscaledImage

import java.awt.image.ImageFilter; //導入依賴的package包/類
public BufferedImage getGrayscaledImage(BufferedImage coloredImage) {
    ImageFilter filter = new ImageFilter(){
        public final int filterRGB(int x, int y, int rgb)
        {
            //TODO - optimization? Bit shifts, not this shits
            Color currentColor = new Color(rgb);
            if(currentColor.getRed() < 2 && currentColor.getGreen() < 2 && currentColor.getBlue() < 2) {
                return new Color(rgb).darker().getRGB();
            }

            return Color.WHITE.getRGB();
        }
    };

    ImageProducer producer = new FilteredImageSource(coloredImage.getSource(), filter);
    Image image = Toolkit.getDefaultToolkit().createImage(producer);
    return toBufferedImage(image);
}
 
開發者ID:corydissinger,項目名稱:mtgo-best-bot,代碼行數:19,代碼來源:ImagePreProcessor.java

示例3: getDisabledIcon

import java.awt.image.ImageFilter; //導入依賴的package包/類
/**
 * {@inheritDoc}
 *
 * @since 1.6
 */
public Icon getDisabledIcon(JComponent component, Icon icon) {
    // if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
    // client property set to Boolean.TRUE, then use the new
    // hi res algorithm for creating the disabled icon (used
    // in particular by the WindowsFileChooserUI class)
    if (icon != null
            && component != null
            && Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
            && icon.getIconWidth() > 0
            && icon.getIconHeight() > 0) {
        BufferedImage img = new BufferedImage(icon.getIconWidth(),
                icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
        icon.paintIcon(component, img.getGraphics(), 0, 0);
        ImageFilter filter = new RGBGrayFilter();
        ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
        Image resultImage = component.createImage(producer);
        return new ImageIconUIResource(resultImage);
    }
    return super.getDisabledIcon(component, icon);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:WindowsLookAndFeel.java

示例4: makeColorTransparent

import java.awt.image.ImageFilter; //導入依賴的package包/類
public static Image makeColorTransparent(Image im, final Color color) {
    //(C)
    //Copiado da internet: 13/02/2011 - http://www.rgagnon.com/javadetails/java-0265.html e http://www.coderanch.com/t/331731/GUI/java/Resize-ImageIcon
    //

    ImageFilter filter = new RGBImageFilter() {
        // the color we are looking for... Alpha bits are set to opaque

        public int markerRGB = color.getRGB() | 0xFF000000;

        @Override
        public final int filterRGB(int x, int y, int rgb) {
            if ((rgb | 0xFF000000) == markerRGB) {
                // Mark the alpha bits as zero - transparent
                return 0x00FFFFFF & rgb;
            } else {
                // nothing to do
                return rgb;
            }
        }
    };

    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}
 
開發者ID:chcandido,項目名稱:brModelo,代碼行數:26,代碼來源:TratadorDeImagens.java

示例5: buildInitialFactories

import java.awt.image.ImageFilter; //導入依賴的package包/類
@SuppressWarnings("deprecation")
protected void buildInitialFactories() {
       int minWordLength = 7;
       int maxWordLength = 7;
       int fontSize = 36;
       int imageWidth = 300;
       int imageHeight = 90;
       WordGenerator wordGenerator = new RandomWordGenerator("0123456789ABCDEFGHIJKLTYREWSZabcdefghjkmnpqrstuvwxyz");
       TextPaster randomPaster = new DecoratedRandomTextPaster(
       		minWordLength,
               maxWordLength, 
               new RandomListColorGenerator(new Color[]{
               		new Color(23, 170, 27), new Color(220, 34, 11),
               		new Color(23, 67, 172)}), new TextDecorator[]{});
       BackgroundGenerator background = new UniColorBackgroundGenerator(imageWidth, imageHeight, Color.GREEN);
       FontGenerator font = new RandomFontGenerator(fontSize, fontSize,
               new Font[]{new Font("Calibri", Font.BOLD, fontSize),
                       new Font("Times New Roman", Font.PLAIN, fontSize),
                       new Font("Arial", Font.BOLD, fontSize)});
       ImageDeformation postDef = new ImageDeformationByFilters(new ImageFilter[]{});
       ImageDeformation backDef = new ImageDeformationByFilters(new ImageFilter[]{});
       ImageDeformation textDef = new ImageDeformationByFilters(new ImageFilter[]{});
       WordToImage word2image = new DeformedComposedWordToImage(font,
               background, randomPaster, backDef, textDef, postDef);
       addFactory(new GimpyFactory(wordGenerator, word2image));
   }
 
開發者ID:PacktPublishing,項目名稱:Spring-MVC-Blueprints,代碼行數:27,代碼來源:CFSJCaptchaEngine.java

示例6: makeColorTransparent

import java.awt.image.ImageFilter; //導入依賴的package包/類
public static BufferedImage makeColorTransparent(BufferedImage im, final Color color) {
	ImageFilter filter = new RGBImageFilter() {

		public int markerRGB = color.getRGB() | 0xFF000000;

		public final int filterRGB(int x, int y, int rgb) {
			if ((rgb | 0xFF000000) == markerRGB) {
				return 0x00FFFFFF & rgb;
			} else {
				return rgb;
			}
		}
	};

	return imageToBufferedImage(
			Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(im.getSource(), filter)));
}
 
開發者ID:kfricilone,項目名稱:OpenRS,代碼行數:18,代碼來源:ImageUtils.java

示例7: cut

import java.awt.image.ImageFilter; //導入依賴的package包/類
/**
 * 圖像切割(指定切片的寬度和高度)
 * @param bi 原圖像
 * @param x 裁剪原圖像起點坐標X
 * @param y 裁剪原圖像起點坐標Y
 * @param width 目標切片寬度
 * @param height 目標切片高度
 * @return
 */
public static BufferedImage cut(BufferedImage bi,int x, int y, int width, int height) {

    BufferedImage tag = new BufferedImage(width, height,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = tag.createGraphics();
    tag = g2.getDeviceConfiguration().createCompatibleImage(width, height,
            Transparency.TRANSLUCENT);
    g2.dispose();
    g2 = tag.createGraphics();

    int srcWidth = bi.getHeight(); // 源圖寬度
    int srcHeight = bi.getWidth(); // 源圖高度
    if (srcWidth > 0 && srcHeight > 0) {
        ImageFilter cropFilter = new CropImageFilter(x, y, width, height);
        Image img = Toolkit.getDefaultToolkit().createImage(
                new FilteredImageSource(bi.getSource(),cropFilter));
        g2.drawImage(img, 0, 0, width, height, null); // 繪製切割後的圖
        g2.dispose();
    }
    return tag;
}
 
開發者ID:QianLongGit,項目名稱:imageServer,代碼行數:31,代碼來源:ImageUtil.java

示例8: cut

import java.awt.image.ImageFilter; //導入依賴的package包/類
/**
 * 圖像切割(按指定起點坐標和寬高切割)
 * @param srcImg 源圖像地址
 * @param outImg 切片後的圖像地址
 * @param x 目標切片起點坐標X
 * @param y 目標切片起點坐標Y
 * @param width 目標切片寬度
 * @param height 目標切片高度
 * @param imageType 圖片類型
 */
public static void cut(File srcImg, File outImg, int x, int y, int width, int height,String imageType) throws Exception{
	//讀取源圖像
	BufferedImage bi = ImageIO.read(srcImg);
	int srcWidth = bi.getHeight();//源圖寬度
	int srcHeight = bi.getWidth();//源圖高度
	if (srcWidth > 0 && srcHeight > 0) {
		Image image = bi.getScaledInstance(srcWidth, srcHeight,Image.SCALE_DEFAULT);
		//四個參數分別為圖像起點坐標和寬高
		//即:CropImageFilter(int x,int y,int width,int height)
		ImageFilter cropFilter = new CropImageFilter(x, y, width,height);
		Image img = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(image.getSource(), cropFilter));
		BufferedImage tag = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
		Graphics g = tag.getGraphics();
		g.drawImage(img, 0, 0, width, height, null);//繪製切割後的圖
		g.dispose();
		//輸出為文件
		ImageIO.write(tag, imageType, outImg);
	}
}
 
開發者ID:tank2140896,項目名稱:JavaWeb,代碼行數:30,代碼來源:ImageUtils.java

示例9: makeColorTransparent

import java.awt.image.ImageFilter; //導入依賴的package包/類
public static Image makeColorTransparent(final BufferedImage im, final Color color) {
	final ImageFilter filter = new RGBImageFilter() {
		// the color we are looking for... Alpha bits are set to opaque
		public int markerRGB = color.getRGB() | 0xFFFFFFFF;

		public final int filterRGB(final int x, final int y, final int rgb) {
			if ((rgb | 0xFF000000) == markerRGB) {
				// Mark the alpha bits as zero - transparent
				return 0x00FFFFFF & rgb;
			} else {
				// nothing to do
				return rgb;
			}
		}
	};

	final ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
	return Toolkit.getDefaultToolkit().createImage(ip);
}
 
開發者ID:SynBioDex,項目名稱:SBOLDesigner,代碼行數:20,代碼來源:Images.java

示例10: setTransparentColor

import java.awt.image.ImageFilter; //導入依賴的package包/類
/**
 * 
 * @param im
 * @param color
 * @return
 */
public static Image setTransparentColor(BufferedImage im, final Color color) {
	ImageFilter filter = new RGBImageFilter() {

		// the color we are looking for... Alpha bits are set to opaque
		public int markerRGB = color.getRGB() | 0xFF000000;

		public final int filterRGB(int x, int y, int rgb) {
			if ((rgb | 0xFF000000) == markerRGB) {
				// Mark the alpha bits as zero - transparent
				return 0x00FFFFFF & rgb;
			} else {
				// nothing to do
				return rgb;
			}
		}
	};

	ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
	return Toolkit.getDefaultToolkit().createImage(ip);
}
 
開發者ID:TKnudsen,項目名稱:ComplexDataObject,代碼行數:27,代碼來源:BufferedImageTools.java

示例11: makeColorTransparent

import java.awt.image.ImageFilter; //導入依賴的package包/類
public static Image makeColorTransparent(BufferedImage im, final Color color) {
    ImageFilter filter = new RGBImageFilter() {

        // the color we are looking for... Alpha bits are set to opaque
        @Override
        public int filterRGB(int x, int y, int rgb) {
            int markerRGB = color.getRGB() | 0xFF000000;

            if ((rgb | 0xFF000000) == markerRGB) {
                // Mark the alpha bits as zero - transparent
                return 0x00FFFFFF & rgb;
            } else {
                // nothing to do
                return rgb;
            }
        }
    };

    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}
 
開發者ID:ZenHarbinger,項目名稱:torgo,代碼行數:22,代碼來源:ImageUtils.java

示例12: transformColorToTransparency

import java.awt.image.ImageFilter; //導入依賴的package包/類
private Image transformColorToTransparency(BufferedImage image, Color color)
{
  ImageFilter filter = new RGBImageFilter()
  {
    public final int filterRGB(int x, int y, int rgb)
    {
    	if (rgb == color.getRGB()) {
    		return new Color(0, 0, 0, 0).getRGB();
    	} else {
    		return rgb;
    	}
    }
  };

  ImageProducer ip = new FilteredImageSource(image.getSource(), filter);
  return Toolkit.getDefaultToolkit().createImage(ip);
}
 
開發者ID:WorldGrower,項目名稱:WorldGrower,代碼行數:18,代碼來源:ImageInfoReader.java

示例13: makeColorTransparent

import java.awt.image.ImageFilter; //導入依賴的package包/類
/**
 * Make a color of a image transparent
 *
 * @param im The image
 * @param color The color
 * @return Result image
 */
public static Image makeColorTransparent(BufferedImage im, final Color color) {
    ImageFilter filter = new RGBImageFilter() {
        // the color we are looking for... Alpha bits are set to opaque
        public int markerRGB = color.getRGB() | 0xFF000000;

        @Override
        public final int filterRGB(int x, int y, int rgb) {
            if ((rgb | 0xFF000000) == markerRGB) {
                // Mark the alpha bits as zero - transparent
                return 0x00FFFFFF & rgb;
            } else {
                // nothing to do
                return rgb;
            }
        }
    };

    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}
 
開發者ID:meteoinfo,項目名稱:MeteoInfoLib,代碼行數:28,代碼來源:GlobalUtil.java

示例14: makeColorTransparent

import java.awt.image.ImageFilter; //導入依賴的package包/類
public static Image makeColorTransparent(Image im, final Color color) {
	ImageFilter filter = new RGBImageFilter() {
		// the color we are looking for... Alpha bits are set to opaque
		public int markerRGB = color.getRGB() | 0xFF000000;

		public final int filterRGB(int x, int y, int rgb) {
			if ((rgb | 0xFF000000) == markerRGB) {
				// Mark the alpha bits as zero - transparent
				return 0x00FFFFFF & rgb;
			} else {
				// nothing to do
				return rgb;
			}
		}
	};

	ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
	return Toolkit.getDefaultToolkit().createImage(ip);
}
 
開發者ID:bh4017,項目名稱:mobac,代碼行數:20,代碼來源:OpenSeaMap.java

示例15: makeColorTransparent

import java.awt.image.ImageFilter; //導入依賴的package包/類
public static Image makeColorTransparent(Image im, final Color color, final int alpha) {

		final ImageFilter filter = new RGBImageFilter() {

			// the color we are looking for... Alpha bits are set to opaque
			public int markerRGB = color.getRGB() | 0xFF000000;

			public final int filterRGB(int x, int y, int rgb) {
				if ( ( rgb | 0xFF000000 ) == markerRGB ) {
					// Mark the alpha bits as zero - transparent
					return (0x00FFFFFF | (alpha << 24)) & rgb;
				}
				else {
					// nothing to do
					return rgb;
				}
			}
		}; 

		ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
		return Toolkit.getDefaultToolkit().createImage(ip);
	}
 
開發者ID:jordanywhite,項目名稱:SquaresInteractive,代碼行數:23,代碼來源:Transparency.java


注:本文中的java.awt.image.ImageFilter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。