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


Java AffineTransformOp.filter方法代码示例

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


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

示例1: generateIdenticon

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
/**
 * Code taken from: <a href="https://stackoverflow.com/a/40699460">Stackoverflow answer from Kevin G. based on code from davidhampgonsalves.com/Identicons</a>
 * Comments and slight modifications added.
 */
public static javafx.scene.image.Image generateIdenticon(String text, int image_width, int image_height) throws IOException {
	// If the input name/text is null or empty no image can be created.
	if (text == null || text.length() < 3) {
		return null;
	}

	int width = 5, height = 5;

	byte[] hash = text.getBytes();

	BufferedImage identicon = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
	WritableRaster raster = identicon.getRaster();

	int [] background = new int [] {255,255,255, 0};
	int [] foreground = new int [] {hash[0] & 255, hash[1] & 255, hash[2] & 255, 255};

	for(int x=0 ; x < width ; x++) {
		//Enforce horizontal symmetry
		int i = x < 3 ? x : 4 - x;
		for(int y=0 ; y < height; y++) {
			int [] pixelColor;
			//toggle pixels based on bit being on/off
			if((hash[i] >> y & 1) == 1)
				pixelColor = foreground;
			else
				pixelColor = background;
			raster.setPixel(x, y, pixelColor);
		}
	}

	BufferedImage finalImage = new BufferedImage(image_width, image_height, BufferedImage.TYPE_INT_ARGB);

	//Scale image to the size you want
	AffineTransform at = new AffineTransform();
	at.scale(image_width / width, image_height / height);
	AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
	finalImage = op.filter(identicon, finalImage);

	// Convert BufferedImage to javafx image
	return createImage(finalImage);
}
 
开发者ID:Gurgy,项目名称:Cypher,代码行数:46,代码来源:Util.java

示例2: applyTransformations

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
/**
 * Flips and scales the image.
 *
 * @return
 *         The flipped and scaled image.
 */
private BufferedImage applyTransformations() {
    final AffineTransform tx;

    if (flipHorizontally && flipVertically) {
        tx = AffineTransform.getScaleInstance(-scaleX, -scaleY);
        tx.translate(-image.getWidth(), -image.getHeight());
    } else if (flipHorizontally) {
        tx = AffineTransform.getScaleInstance(-scaleX, scaleY);
        tx.translate(-image.getWidth(), 0);
    } else if(flipVertically) {
        tx = AffineTransform.getScaleInstance(scaleX, -scaleY);
        tx.translate(0, -image.getHeight());
    } else {
        tx = AffineTransform.getScaleInstance(scaleX, scaleY);
    }

    final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    return op.filter(image, null);
}
 
开发者ID:Valkryst,项目名称:VTerminal,代码行数:26,代码来源:ImagePrinter.java

示例3: addShadow

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
/**
 * Adds a shadow effect by executing the following steps: 1. Transform visible
 * pixels to a semi-transparent black 2. Flip the image vertically 3. Scale it
 * down 4. Render original image and shadow on a buffered image
 *
 * @param image
 *          the image
 * @param xOffset
 *          the x offset
 * @param yOffset
 *          the y offset
 * @return the buffered image
 */
public static BufferedImage addShadow(final BufferedImage image, final int xOffset, final int yOffset) {
  if (image == null) {
    return image;
  }

  // Transform visible pixels to a semi-transparent black
  final BufferedImage shadowImage = flashVisiblePixels(image, new Color(0, 0, 0, 30));
  if (shadowImage == null) {
    return image;
  }

  final AffineTransform tx = new AffineTransform();

  // Flip the image vertically
  tx.concatenate(AffineTransform.getScaleInstance(1, -0.15));
  tx.concatenate(AffineTransform.getTranslateInstance(0, -shadowImage.getHeight()));
  final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
  final BufferedImage rotatedImage = op.filter(shadowImage, null);

  final BufferedImage shadow = getCompatibleImage(image.getWidth(), image.getHeight() + rotatedImage.getHeight());
  final Graphics2D g2D = shadow.createGraphics();
  g2D.drawImage(rotatedImage, xOffset, yOffset, null);
  g2D.drawImage(image, 0, 0, null);

  g2D.dispose();

  return shadow;
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:42,代码来源:ImageProcessing.java

示例4: rotate

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
public static BufferedImage rotate(final BufferedImage bufferedImage, final double radians) {

    final AffineTransform tx = new AffineTransform();
    tx.rotate(radians, bufferedImage.getWidth() / 2.0, bufferedImage.getHeight() / 2.0);

    final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
    return op.filter(bufferedImage, null);
  }
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:9,代码来源:ImageProcessing.java

示例5: draw

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
/**
 * Legacy method for drawing 8x8 tiles
 * @param g
 * @param x
 * @param y
 * @param scale
 */
public void draw(Graphics g, int x, int y, int scale) {
	BufferedImage tileimg = getImage();
	BufferedImage scaledimg = new BufferedImage(
			tileimg.getWidth() * scale, tileimg.getHeight() * scale, BufferedImage.TYPE_INT_ARGB);
	AffineTransform at = new AffineTransform();
	at.scale(scale, scale);
	AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
	op.filter(tileimg, scaledimg);
	g.drawImage(scaledimg, x, y, null);
}
 
开发者ID:Goldensunboy,项目名称:WL4Edit,代码行数:18,代码来源:Tile8x8.java

示例6: scale

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
/**
 * Build a scaled version of an image.
 *
 * @param img   image to scale
 * @param ratio scaling ratio
 * @return the scaled image
 */
public static BufferedImage scale (BufferedImage img,
                                   double ratio)
{
    AffineTransform at = AffineTransform.getScaleInstance(ratio, ratio);
    AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
    BufferedImage scaledImg = new BufferedImage(
            (int) Math.ceil(img.getWidth() * ratio),
            (int) Math.ceil(img.getHeight() * ratio),
            img.getType());

    return atop.filter(img, scaledImg);
}
 
开发者ID:Audiveris,项目名称:omr-dataset-tools,代码行数:20,代码来源:SheetProcessor.java

示例7: slant

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
public static BufferedImage slant(BufferedImage image, FlexQuadrilateral quadrilateral, int xTranslation) {
    Point p = new Point(quadrilateral.getBottomLeft().x, quadrilateral.getTopLeft().y);
    double theta = Geometry.theta(quadrilateral.getBottomLeft(), p, quadrilateral.getTopLeft());

    AffineTransform transform = AffineTransform.getTranslateInstance(xTranslation, 0);
    transform.shear(Math.tan(theta), 0);

    transform.translate(xTranslation, 0);
    AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
    return op.filter(image, null);
}
 
开发者ID:defano,项目名称:jmonet,代码行数:12,代码来源:Transform.java

示例8: affineTransform

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
public void affineTransform (double fShxFactor, double fShyFactor) {

        try {
          AffineTransform shearer =
            AffineTransform.getShearInstance (fShxFactor, fShyFactor);
          AffineTransformOp shear_op =
            new AffineTransformOp (shearer, null);
          bufferedImage = shear_op.filter (bufferedImage, null);
        }
        catch (Exception e) {
          System.out.println("Shearing exception = " + e);
        }
      }
 
开发者ID:ZiryLee,项目名称:FileUpload2Spring,代码行数:14,代码来源:EasyImage.java

示例9: resizeImage

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
public static BufferedImage resizeImage(BufferedImage image, int wantedWidth, int wantedHeight) {
    int w = image.getWidth();
    int h = image.getHeight();
    AffineTransform at = new AffineTransform();
    at.scale((double) wantedWidth / (double) w, (double) wantedHeight / (double) h);
    AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);

    BufferedImage rescaledImage = new BufferedImage(wantedWidth, wantedHeight, BufferedImage.TYPE_INT_ARGB);
    rescaledImage = scaleOp.filter(image, rescaledImage);

    return rescaledImage;
}
 
开发者ID:trebonius0,项目名称:Photato,代码行数:13,代码来源:ImageHelper.java

示例10: scaleSmooth

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
private static BufferedImage scaleSmooth(BufferedImage im, double newWidth, double newHeigth)
{
    int w = im.getWidth();
    int h = im.getHeight();
    BufferedImage result = new BufferedImage((int)newWidth, (int)newHeigth, BufferedImage.TYPE_INT_ARGB);
    AffineTransform at = new AffineTransform();
    at.scale(newWidth / w, newHeigth / h);
    AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
    result = scaleOp.filter(im, result);
    return result;
}
 
开发者ID:mirkoruether,项目名称:DigitRecognizer,代码行数:12,代码来源:DigitManipulator.java

示例11: run

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
@Override
public void run() {
    BufferedImage img = new BufferedImage(display.getWidth(), display.getHeight(), BufferedImage.TYPE_INT_RGB);
    for (int y = 0; y < display.getHeight(); y++) {
        for (int x = 0; x < display.getWidth(); x++) {
            int idx = getIndex(x, y);
            int nIdx = 3 * idx;
            int r = ((int) (rgbValues[nIdx++] * 255)); // red component 0...255
            int g = ((int) (rgbValues[nIdx++] * 255)); // green component 0...255
            int b = ((int) (rgbValues[nIdx] * 255)); // blue component 0...255
            int col = (r << 16) | (g << 8) | b;
            img.setRGB(x, y, col);
        }
    }
    AffineTransform tx = AffineTransform.getScaleInstance(1, -1);  //alligns the image correctly
    tx.translate(0, -img.getHeight(null));
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    img = op.filter(img, null);
    SimpleDateFormat sdfDate = new SimpleDateFormat("_yyyy_MM_dd_HH_mm_ss");//dd/MM/yyyy
    Date now = new Date();
    String strDate = sdfDate.format(now);
    try {
        ImageIO.write(img, "png", new File(String.format("%s/ImageCreator%s.png", path, strDate)));
    } catch (IOException ex) {
        log.warning("can not save Image, Error: " + ex.toString());
    }
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:28,代码来源:ImageCreator.java

示例12: scale

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
/**
 * 缩放图片
 *
 * @param imgPath 源图片绝对路径
 * @param disPath 目标图片绝对路径
 * @param height 目标高度
 * @param width 目标宽度
 * @param whiteFill 是否补白
 */
public final static void scale(String imgPath, String disPath, int height, int width, boolean whiteFill) {
    try {
        double ratio = 0.0;
        File file = new File(imgPath);
        BufferedImage bufferedImage = ImageIO.read(file);
        Image tempImg = bufferedImage.getScaledInstance(width, height, BufferedImage.SCALE_SMOOTH);
        // 计算比例
        if ((bufferedImage.getHeight() > height) || (bufferedImage.getWidth() > width)) {
            double ratioV = (new Integer(height).doubleValue() / bufferedImage.getHeight());
            double ratioH = (new Integer(width).doubleValue() / bufferedImage.getWidth());
            ratio = Math.max(ratioV, ratioH);
            AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(ratio, ratio), null);
            tempImg = op.filter(bufferedImage, null);
        }
        if (whiteFill) {
            BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = img.createGraphics();
            g.setColor(Color.WHITE);
            g.fillRect(0, 0, width, height);
            if (width == tempImg.getWidth(null)) {
                g.drawImage(tempImg, 0, (height - tempImg.getHeight(null)) / 2, tempImg.getWidth(null), tempImg.getHeight(null), Color.WHITE, null);
            } else {
                g.drawImage(tempImg, (width - tempImg.getWidth(null)) / 2, 0, tempImg.getWidth(null), tempImg.getHeight(null), Color.WHITE, null);
            }
            g.dispose();
            tempImg = img;
        }
        ImageIO.write((BufferedImage)tempImg, "JPEG", new File(disPath));
    } catch (IOException e) {
        //
        e.printStackTrace();
    }
}
 
开发者ID:thundernet8,项目名称:Elune,代码行数:43,代码来源:ImageUtil.java

示例13: testImageTransform

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
public static BufferedImage testImageTransform(BufferedImage image,
                                               AffineTransform transform) {
    AffineTransformOp op =
            new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);

    BufferedImage transformedImage = new BufferedImage(image.getWidth(),
                                                       image.getHeight(),
                                                       image.getType());

    return op.filter(image, transformedImage);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:InvalidTransformParameterTest.java

示例14: testRasterTransform

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
public static Raster testRasterTransform(Raster src, WritableRaster dst,
                                         AffineTransform transform) {
    AffineTransformOp op =
            new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);

    return op.filter(src, dst);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:InvalidTransformParameterTest.java

示例15: scaleImage

import java.awt.image.AffineTransformOp; //导入方法依赖的package包/类
public static BufferedImage scaleImage(final BufferedImage image, final int width, final int height, final boolean keepRatio) {
  if (width == 0 || height == 0 || image == null) {
    return null;
  }

  final int imageWidth = image.getWidth();
  final int imageHeight = image.getHeight();
  double newWidth = width;
  double newHeight = height;
  if (keepRatio) {
    final double ratioWidth = image.getWidth() / (double) image.getHeight();
    final double ratioHeight = image.getHeight() / (double) image.getWidth();

    newHeight = newWidth * ratioHeight;
    if (newHeight > height) {
      newHeight = height;
      newWidth = newHeight * ratioWidth;
    }
  }

  final double scaleX = newWidth / imageWidth;
  final double scaleY = newHeight / imageHeight;
  final AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
  final AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
  final BufferedImage scaled = bilinearScaleOp.filter(image, getCompatibleImage((int) newWidth, (int) newHeight));
  final BufferedImage newImg = getCompatibleImage((int) newWidth, (int) newHeight);
  if (newImg == null) {
    return image;
  }

  final Graphics2D g = (Graphics2D) newImg.getGraphics();
  g.drawImage(scaled, 0, 0, null);
  g.dispose();

  if (newWidth != width || newHeight != height) {
    final BufferedImage wrapperImage = getCompatibleImage(width, height);
    final Graphics2D g2 = (Graphics2D) wrapperImage.getGraphics();
    g2.drawImage(newImg, (int) ((width - newWidth) / 2.0), (int) ((height - newHeight) / 2.0), null);
    g2.dispose();
    return wrapperImage;
  }

  return newImg;
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:45,代码来源:ImageProcessing.java


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