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