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;
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations