Java BufferedImage Operation resampleWithAffineTransformOp(BufferedImage srcImage, double sx, double sy)

Here you can find the source of resampleWithAffineTransformOp(BufferedImage srcImage, double sx, double sy)

Description

resample With Affine Transform Op

License

Open Source License

Declaration

public static final BufferedImage resampleWithAffineTransformOp(BufferedImage srcImage, double sx, double sy) 

Method Source Code

//package com.java2s;

import java.awt.image.BufferedImage;

import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;

public class Main {
    public static final BufferedImage resampleWithAffineTransformOp(BufferedImage srcImage, double sx, double sy) {
        //System.err.println("BufferedImageUtilities.resampleWithAffineTransformOp(): start");
        //long startTime = System.currentTimeMillis();
        AffineTransform transform = AffineTransform.getScaleInstance(sx, sy);
        AffineTransformOp transformOp = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
        BufferedImage dstImage = transformOp.createCompatibleDestImage(srcImage, srcImage.getColorModel()); // otherwise returns, say RGBA even if gray
        dstImage = transformOp.filter(srcImage, dstImage);
        //System.err.println("BufferedImageUtilities.resampleWithAffineTransformOp() elapsed: "+(System.currentTimeMillis()-startTime)+" ms");
        return dstImage;
    }//from w w  w .  j  a v  a  2  s. c o m

    public static final BufferedImage resampleWithAffineTransformOp(BufferedImage srcImage, int dstWidth,
            int dstHeight) {
        //System.err.println("BufferedImageUtilities.resampleWithAffineTransformOp():");
        int srcWidth = srcImage.getWidth();
        int srcHeight = srcImage.getHeight();
        double sx = ((double) dstWidth) / srcWidth;
        double sy = ((double) dstHeight) / srcHeight;
        return resampleWithAffineTransformOp(srcImage, sx, sy);
    }
}

Related

  1. recolor(BufferedImage src, Color sc)
  2. recombine(BufferedImage[][] blocks)
  3. reorientImage(BufferedImage image, boolean yAxisFlipNeeded, int cwRotationNeeded)
  4. repairImage(final BufferedImage bfi, final List order)
  5. resampleImage(BufferedImage image, int height)
  6. revertBlackAndWhite(BufferedImage img)
  7. roate90(BufferedImage src)
  8. sample9Points(BufferedImage src, int x, int y)
  9. scanFill(BufferedImage sourceImage)