use of java.awt.image.AffineTransformOp in project Lucee by lucee.
the class Image method rgb.
public void rgb() throws ExpressionException {
BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_BYTE_INDEXED);
Graphics2D graphics = img.createGraphics();
graphics.drawImage(image(), new AffineTransformOp(AffineTransform.getTranslateInstance(0.0, 0.0), 1), 0, 0);
graphics.dispose();
image(img);
}
use of java.awt.image.AffineTransformOp in project litiengine by gurkenlabs.
the class ImageProcessing method addShadow.
/**
* 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;
}
final int width = image.getWidth();
final int height = image.getHeight();
if (width == 0 || height == 0) {
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(width, height + rotatedImage.getHeight() * 2);
final Graphics2D g2D = shadow.createGraphics();
g2D.drawImage(rotatedImage, xOffset, yOffset + rotatedImage.getHeight(), null);
g2D.drawImage(image, 0, rotatedImage.getHeight(), null);
g2D.dispose();
return shadow;
}
use of java.awt.image.AffineTransformOp in project jdk8u_jdk by JetBrains.
the class ImagingLib method filter.
public static BufferedImage filter(BufferedImageOp op, BufferedImage src, BufferedImage dst) {
if (verbose) {
System.out.println("in filter and op is " + op + "bufimage is " + src + " and " + dst);
}
if (useLib == false) {
return null;
}
// Create the destination image
if (dst == null) {
dst = op.createCompatibleDestImage(src, null);
}
BufferedImage retBI = null;
switch(getNativeOpIndex(op.getClass())) {
case LOOKUP_OP:
// REMIND: Fix this!
LookupTable table = ((LookupOp) op).getTable();
if (table.getOffset() != 0) {
// Right now the native code doesn't support offsets
return null;
}
if (table instanceof ByteLookupTable) {
ByteLookupTable bt = (ByteLookupTable) table;
if (lookupByteBI(src, dst, bt.getTable()) > 0) {
retBI = dst;
}
}
break;
case AFFINE_OP:
AffineTransformOp bOp = (AffineTransformOp) op;
double[] matrix = new double[6];
AffineTransform xform = bOp.getTransform();
bOp.getTransform().getMatrix(matrix);
if (transformBI(src, dst, matrix, bOp.getInterpolationType()) > 0) {
retBI = dst;
}
break;
case CONVOLVE_OP:
ConvolveOp cOp = (ConvolveOp) op;
if (convolveBI(src, dst, cOp.getKernel(), cOp.getEdgeCondition()) > 0) {
retBI = dst;
}
break;
default:
break;
}
if (retBI != null) {
SunWritableRaster.markDirty(retBI);
}
return retBI;
}
use of java.awt.image.AffineTransformOp in project live-image-editor by alejandro-du.
the class LiveImageEditor method transformImage.
private InputStream transformImage() throws IOException {
BufferedImage src = ImageIO.read(new ByteArrayInputStream(imageData));
double aspectRatio = cropWidth / cropHeight;
int destWidth = src.getWidth();
int destHeight = (int) (src.getWidth() / aspectRatio);
BufferedImage dest = new BufferedImage(destWidth, destHeight, src.getType());
int halfW = src.getWidth() / 2;
int halfH = src.getHeight() / 2;
AffineTransform restoreCenter = AffineTransform.getTranslateInstance(halfW, halfH);
AffineTransform rotate = AffineTransform.getRotateInstance(getRotate());
AffineTransform scale = AffineTransform.getScaleInstance(getScale(), getScale());
AffineTransform translate = AffineTransform.getTranslateInstance(src.getWidth() * getTranslateX(), src.getWidth() / aspectRatio * getTranslateY());
AffineTransform translateCenter = AffineTransform.getTranslateInstance(-halfW, -halfH);
AffineTransform transform = new AffineTransform();
transform.concatenate(restoreCenter);
transform.concatenate(translate);
transform.concatenate(rotate);
transform.concatenate(scale);
transform.concatenate(translateCenter);
AffineTransformOp operation = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
operation.filter(src, dest);
Graphics2D g2d = dest.createGraphics();
g2d.setPaint(new Color(red, green, blue));
g2d.fillRect(0, 0, destWidth, destHeight);
g2d.drawImage(src, transform, null);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(dest, "png", outputStream);
return new ByteArrayInputStream(outputStream.toByteArray());
}
use of java.awt.image.AffineTransformOp in project vip by guangdada.
the class ImgQrTool method scale.
/**
* 把传入的原始图像按高度和宽度进行缩放,生成符合要求的图标
*
* @param srcImageFile 源文件地址
* @param height 目标高度
* @param width 目标宽度
* @param hasFiller 比例不对时是否需要补白:true为补白; false为不补白;
* @throws IOException
*/
private static BufferedImage scale(String srcImageFile, int height, int width, boolean hasFiller) throws IOException {
// 缩放比例
double ratio = 0.0;
File file = new File(srcImageFile);
BufferedImage srcImage = ImageIO.read(file);
Image destImage = srcImage.getScaledInstance(width, height, BufferedImage.SCALE_SMOOTH);
// 计算比例
if ((srcImage.getHeight() > height) || (srcImage.getWidth() > width)) {
if (srcImage.getHeight() > srcImage.getWidth()) {
ratio = (new Integer(height)).doubleValue() / srcImage.getHeight();
} else {
ratio = (new Integer(width)).doubleValue() / srcImage.getWidth();
}
AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(ratio, ratio), null);
destImage = op.filter(srcImage, null);
}
if (hasFiller) {
// 补白
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphic = image.createGraphics();
graphic.setColor(Color.white);
graphic.fillRect(0, 0, width, height);
if (width == destImage.getWidth(null))
graphic.drawImage(destImage, 0, (height - destImage.getHeight(null)) / 2, destImage.getWidth(null), destImage.getHeight(null), Color.white, null);
else
graphic.drawImage(destImage, (width - destImage.getWidth(null)) / 2, 0, destImage.getWidth(null), destImage.getHeight(null), Color.white, null);
graphic.dispose();
destImage = image;
}
return (BufferedImage) destImage;
}
Aggregations