Search in sources :

Example 1 with AffineTransformOp

use of java.awt.image.AffineTransformOp in project jmonkeyengine by jMonkeyEngine.

the class ImageUtils method resizeTo.

/**
     * Resizes the image to the given width and height.
     * @param source
     *            the source image (this remains untouched, the new image instance is created)
     * @param width
     *            the target image width
     * @param height
     *            the target image height
     * @return the resized image
     */
public static Image resizeTo(Image source, int width, int height) {
    BufferedImage sourceImage = ImageToAwt.convert(source, false, false, 0);
    double scaleX = width / (double) sourceImage.getWidth();
    double scaleY = height / (double) sourceImage.getHeight();
    AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
    AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
    BufferedImage scaledImage = bilinearScaleOp.filter(sourceImage, new BufferedImage(width, height, sourceImage.getType()));
    return ImageUtils.toJmeImage(scaledImage, source.getFormat());
}
Also used : AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 2 with AffineTransformOp

use of java.awt.image.AffineTransformOp in project Overloaded by CJ-MC-Mods.

the class CompressedBlockAssets method scaleToWidth.

private static BufferedImage scaleToWidth(@Nonnull BufferedImage original, int width) {
    double scale = original.getWidth() / (double) width;
    AffineTransform at = new AffineTransform();
    at.scale(1 / scale, 1 / scale);
    AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
    return scaleOp.filter(original, null);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 3 with AffineTransformOp

use of java.awt.image.AffineTransformOp in project zxing by zxing.

the class AbstractBlackBoxTestCase method rotateImage.

protected static BufferedImage rotateImage(BufferedImage original, float degrees) {
    if (degrees == 0.0f) {
        return original;
    }
    switch(original.getType()) {
        case BufferedImage.TYPE_BYTE_INDEXED:
        case BufferedImage.TYPE_BYTE_BINARY:
            BufferedImage argb = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_ARGB);
            Graphics g = argb.createGraphics();
            g.drawImage(original, 0, 0, null);
            g.dispose();
            original = argb;
            break;
    }
    double radians = Math.toRadians(degrees);
    // Transform simply to find out the new bounding box (don't actually run the image through it)
    AffineTransform at = new AffineTransform();
    at.rotate(radians, original.getWidth() / 2.0, original.getHeight() / 2.0);
    BufferedImageOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
    RectangularShape r = op.getBounds2D(original);
    int width = (int) Math.ceil(r.getWidth());
    int height = (int) Math.ceil(r.getHeight());
    // Real transform, now that we know the size of the new image and how to translate after we rotate
    // to keep it centered
    at = new AffineTransform();
    at.rotate(radians, width / 2.0, height / 2.0);
    at.translate((width - original.getWidth()) / 2.0, (height - original.getHeight()) / 2.0);
    op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
    return op.filter(original, new BufferedImage(width, height, original.getType()));
}
Also used : Graphics(java.awt.Graphics) BufferedImageOp(java.awt.image.BufferedImageOp) RectangularShape(java.awt.geom.RectangularShape) AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 4 with AffineTransformOp

use of java.awt.image.AffineTransformOp in project poi by apache.

the class BitmapImageRenderer method getImage.

@Override
public BufferedImage getImage(Dimension dim) {
    double w_old = img.getWidth();
    double h_old = img.getHeight();
    BufferedImage scaled = new BufferedImage((int) w_old, (int) h_old, BufferedImage.TYPE_INT_ARGB);
    double w_new = dim.getWidth();
    double h_new = dim.getHeight();
    AffineTransform at = new AffineTransform();
    at.scale(w_new / w_old, h_new / h_old);
    AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
    scaleOp.filter(img, scaled);
    return scaled;
}
Also used : AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 5 with AffineTransformOp

use of java.awt.image.AffineTransformOp in project jdk8u_jdk by JetBrains.

the class D3DDrawImage method transformImage.

@Override
public void transformImage(SunGraphics2D sg, BufferedImage img, BufferedImageOp op, int x, int y) {
    if (op != null) {
        if (op instanceof AffineTransformOp) {
            AffineTransformOp atop = (AffineTransformOp) op;
            transformImage(sg, img, x, y, atop.getTransform(), atop.getInterpolationType());
            return;
        } else {
            if (D3DBufImgOps.renderImageWithOp(sg, img, op, x, y)) {
                return;
            }
        }
        img = op.filter(img, null);
    }
    copyImage(sg, img, x, y, null);
}
Also used : AffineTransformOp(java.awt.image.AffineTransformOp)

Aggregations

AffineTransformOp (java.awt.image.AffineTransformOp)48 AffineTransform (java.awt.geom.AffineTransform)31 BufferedImage (java.awt.image.BufferedImage)29 Graphics2D (java.awt.Graphics2D)20 IOException (java.io.IOException)4 Rectangle2D (java.awt.geom.Rectangle2D)3 WritableRaster (java.awt.image.WritableRaster)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Color (java.awt.Color)2 GradientPaint (java.awt.GradientPaint)2 Image (java.awt.Image)2 RenderingHints (java.awt.RenderingHints)2 ByteLookupTable (java.awt.image.ByteLookupTable)2 ConvolveOp (java.awt.image.ConvolveOp)2 LookupOp (java.awt.image.LookupOp)2 LookupTable (java.awt.image.LookupTable)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 ImageException (cbit.image.ImageException)1 GeometryException (cbit.vcell.geometry.GeometryException)1