Search in sources :

Example 26 with AffineTransformOp

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

the class TextureUnpacker method extractImage.

/** Extract an image from a texture atlas.
	 * @param page The image file related to the page the region is in
	 * @param region The region to extract
	 * @param outputDirFile The output directory
	 * @param padding padding (in pixels) to apply to the image
	 * @return The extracted image */
private BufferedImage extractImage(BufferedImage page, Region region, File outputDirFile, int padding) {
    BufferedImage splitImage = null;
    // get the needed part of the page and rotate if needed
    if (region.rotate) {
        BufferedImage srcImage = page.getSubimage(region.left, region.top, region.height, region.width);
        splitImage = new BufferedImage(region.width, region.height, page.getType());
        AffineTransform transform = new AffineTransform();
        transform.rotate(Math.toRadians(90.0));
        transform.translate(0, -region.width);
        AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
        op.filter(srcImage, splitImage);
    } else {
        splitImage = page.getSubimage(region.left, region.top, region.width, region.height);
    }
    // draw the image to a bigger one if padding is needed
    if (padding > 0) {
        BufferedImage paddedImage = new BufferedImage(splitImage.getWidth() + padding * 2, splitImage.getHeight() + padding * 2, page.getType());
        Graphics2D g2 = paddedImage.createGraphics();
        g2.drawImage(splitImage, padding, padding, null);
        g2.dispose();
        return paddedImage;
    } else {
        return splitImage;
    }
}
Also used : AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage) AffineTransformOp(java.awt.image.AffineTransformOp) Graphics2D(java.awt.Graphics2D)

Example 27 with AffineTransformOp

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

the class InvalidTransformParameterTest method testImageTransform.

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);
}
Also used : BufferedImage(java.awt.image.BufferedImage) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 28 with AffineTransformOp

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

the class OGLDrawImage 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 (OGLBufImgOps.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)

Example 29 with AffineTransformOp

use of java.awt.image.AffineTransformOp in project lionengine by b3dgs.

the class GraphicAwt method drawImage.

@Override
public void drawImage(ImageSurface image, Transform transform, int x, int y) {
    if (lastTransform != transform) {
        lastTransform = transform;
        final AffineTransform at = new AffineTransform();
        at.scale(transform.getScaleX(), transform.getScaleY());
        final int interpolation = UtilMath.clamp(transform.getInterpolation(), AffineTransformOp.TYPE_NEAREST_NEIGHBOR, AffineTransformOp.TYPE_BICUBIC);
        op = new AffineTransformOp(at, interpolation);
    }
    g.drawImage((BufferedImage) image.getSurface(), op, x, y);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) GradientPaint(java.awt.GradientPaint) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 30 with AffineTransformOp

use of java.awt.image.AffineTransformOp in project Lucee by lucee.

the class Image method translate.

public void translate(int xtrans, int ytrans, Object interpolation) throws ExpressionException {
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION, interpolation);
    if (interpolation != RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) {
        hints.add(new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(1)));
    }
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(image());
    BufferedImage img = JAI.create("translate", pb).getAsBufferedImage();
    Graphics2D graphics = img.createGraphics();
    graphics.clearRect(0, 0, img.getWidth(), img.getHeight());
    AffineTransform at = new AffineTransform();
    at.setToIdentity();
    graphics.drawImage(image(), new AffineTransformOp(at, hints), xtrans, ytrans);
    graphics.dispose();
    image(img);
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) AffineTransform(java.awt.geom.AffineTransform) RenderingHints(java.awt.RenderingHints) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) 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