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


Java AreaAveragingScaleFilter类代码示例

本文整理汇总了Java中java.awt.image.AreaAveragingScaleFilter的典型用法代码示例。如果您正苦于以下问题:Java AreaAveragingScaleFilter类的具体用法?Java AreaAveragingScaleFilter怎么用?Java AreaAveragingScaleFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createThumbnail

import java.awt.image.AreaAveragingScaleFilter; //导入依赖的package包/类
public static BufferedImage createThumbnail(BufferedImage image, int maxWidth, int maxHeight) {
    if (image == null) {
        return null;
    }
    final double widthRate = (double) maxWidth / image.getWidth();
    final double heightRate = (double) maxHeight / image.getHeight();
    double rate = 1;
    if (widthRate > heightRate) {
        rate = heightRate;
    } else {
        rate = widthRate;
    }
    int type = image.getType();
    if (type == BufferedImage.TYPE_CUSTOM) {
        type = BufferedImage.TYPE_INT_ARGB;
    }
    final int w = (int) (image.getWidth() * rate);
    final int h = (int) (image.getHeight() * rate);
    final Image newImage = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(image.getSource(), new AreaAveragingScaleFilter(w, h)));
    return imageToBufferedImage(newImage);
}
 
开发者ID:shuichi,项目名称:MediaMatrix,代码行数:22,代码来源:ImageUtilities.java

示例2: main

import java.awt.image.AreaAveragingScaleFilter; //导入依赖的package包/类
public static void main(String args[]) {
    new AreaAveragingScaleFilter(100, 100).clone();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:HeadlessAreaAveragingScaleFilter.java

示例3: resizeImage

import java.awt.image.AreaAveragingScaleFilter; //导入依赖的package包/类
public static BufferedImage resizeImage(BufferedImage image, int drawingWidth, int drawingHeight, CenterOption centerOption, ScaleOption scaleOption){

		int imageWidth=image.getWidth();
		int imageHeight=image.getHeight();

		double widthScale = drawingWidth/(double) imageWidth;
		double heightScale = drawingHeight/(double) imageHeight;
		double scale=Math.min(widthScale, heightScale);
		
		int scaleWidth=(int) (imageWidth*scale);
		int scaleHeight=(int) (imageHeight*scale); 
		
		BufferedImage resizedImage = new BufferedImage(scaleWidth, scaleHeight, BufferedImage.TYPE_INT_ARGB);
	    Graphics2D g = resizedImage.createGraphics();
	    
		if (scaleOption==ScaleOption.SCALE_AREA_AVERAGING){
			ImageProducer prod = new FilteredImageSource(image.getSource(), new AreaAveragingScaleFilter(scaleWidth, scaleHeight));
			Image img = Toolkit.getDefaultToolkit().createImage(prod);
		    g.drawImage(img, 0, 0, scaleWidth, scaleHeight, null);  // it's already scaled
		} else {
			if (scaleOption==ScaleOption.SCALE_NEAREST_NEIGHBOR) {
				g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);	
			} else if (scaleOption==ScaleOption.SCALE_BICUBIC) {
				g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
			} else if (scaleOption==ScaleOption.SCALE_BILINEAR) {
				g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
			}
		    g.drawImage(image, 0, 0, scaleWidth, scaleHeight, 0, 0, imageWidth, imageHeight, null); 
		}
	    g.dispose();
	    
		int cropWidth = (int) Math.min(scaleWidth, drawingWidth);
		int cropHeight = (int) Math.min(scaleHeight, drawingHeight);
		
		int drawingLeft=0;
		int drawingTop=0;
		if ((centerOption==CenterOption.CENTER_HORIZONTAL) || (centerOption==CenterOption.CENTER_BOTH)){
			drawingLeft=(int) ((drawingWidth-cropWidth)/2.0);
		}
		if ((centerOption==CenterOption.CENTER_VERTICAL) || (centerOption==CenterOption.CENTER_BOTH)){
			drawingTop=(int) ((drawingHeight-cropHeight)/2.0);
		}

		BufferedImage croppedImage = resizedImage.getSubimage(0, 0, cropWidth, cropHeight);
		resizedImage=null;
		
		BufferedImage drawingImage = new BufferedImage(drawingWidth, drawingHeight, BufferedImage.TYPE_INT_ARGB);
		g = drawingImage.createGraphics();
	    g.drawImage(croppedImage, drawingLeft, drawingTop, drawingLeft+cropWidth, drawingTop+cropHeight, 0, 0, cropWidth, cropHeight, null);
	    g.dispose();
	    
	    croppedImage=null;
	    return drawingImage;
	}
 
开发者ID:MHAVLOVICK,项目名称:Sketchy,代码行数:55,代码来源:ImageProcessingThread.java

示例4: resizeImage

import java.awt.image.AreaAveragingScaleFilter; //导入依赖的package包/类
/**
 * 画像をリサイズする
 * 
 * @param inputFile
 *          リサイズ元画像ファイル
 * @param canvasWidth
 *          リサイズ後の画像の幅
 * @param canvasHeight
 *           リサイズ後の画像の高さ
 * @param outputFile
 *          リサイズ後画像ファイル
 * @throws IOException
 */
@VisibleForTesting
void resizeImage(File inputFile, int canvasWidth, int canvasHeight, boolean keepAspectRatio,
    File outputFile) throws IOException {
  BufferedImage inputImage = ImageIO.read(inputFile);

  if (inputImage == null) {
    throw new IOException("ダウンロードした画像ファイル形式が判別できませんでした inputFile:" + inputFile);
  }

  int imageWidth = canvasWidth;
  int imageHeight = canvasHeight;
  int offsetX = 0;
  int offsetY = 0;
  if (keepAspectRatio) {
    if (inputImage.getWidth() * 3 <= inputImage.getHeight() * 4) {
      // 縦長
      imageWidth = imageHeight * inputImage.getHeight() / inputImage.getWidth();
      offsetX = (canvasWidth - imageWidth) / 2;
    } else {
      // 横長
      imageHeight = imageWidth * inputImage.getWidth() / inputImage.getHeight();
      offsetY = (canvasHeight - imageHeight) / 2;
    }
  }

  ImageFilter imageFilter = new AreaAveragingScaleFilter(imageWidth, imageHeight);
  Image middleImage = new Canvas().createImage(new FilteredImageSource(inputImage.getSource(),
      imageFilter));
  BufferedImage outputImage = new BufferedImage(canvasWidth, canvasHeight,
      BufferedImage.TYPE_INT_RGB);
  Graphics2D graphics = outputImage.createGraphics();

  // 透明色が黒く表示されるバグへの対処
  graphics.setColor(Color.WHITE);
  graphics.fill(new Rectangle(canvasWidth, canvasHeight));

  graphics.drawImage(middleImage, offsetX, offsetY, imageWidth, imageHeight, null);
  ImageIO.write(outputImage, "jpeg", outputFile);

  logger.log(Level.INFO, String.format("%d bytes -> %d bytes (%s->%s)", inputFile.length(),
      outputFile.length(), inputFile.getPath(), outputFile.getPath()));
}
 
开发者ID:nodchip,项目名称:QMAClone,代码行数:56,代码来源:ImageUtils.java

示例5: getScaledImage

import java.awt.image.AreaAveragingScaleFilter; //导入依赖的package包/类
/**
 * @param img
 *            to scale
 * @param newWidth
 *            desired width
 * @param newHeight
 *            desired height
 * @return a scaled image
 */
private Image getScaledImage(Image img, int newWidth, int newHeight) {
    ImageFilter filter = new AreaAveragingScaleFilter(newWidth, newHeight);
    ImageProducer prod = new FilteredImageSource(img.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(prod);
}
 
开发者ID:LInE-IME-USP,项目名称:ivp2java,代码行数:15,代码来源:IconButtonUI.java


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