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