/** * Creates a scaled instance of the given {@code BufferedImage}. * * @param pImage the {@code BufferedImage} to scale * @param pWidth width in pixels * @param pHeight height in pixels * @param pHints scaling mHints * * @return a {@code BufferedImage} * * @throws NullPointerException if {@code pImage} is {@code null}. * * @see Image#SCALE_AREA_AVERAGING * @see Image#SCALE_DEFAULT * @see Image#SCALE_FAST * @see Image#SCALE_REPLICATE * @see Image#SCALE_SMOOTH * @see ResampleOp */ public static BufferedImage createResampled(BufferedImage pImage, int pWidth, int pHeight, int pHints) { // Hints are converted between java.awt.Image hints and filter types return new ResampleOp(pWidth, pHeight, convertAWTHints(pHints)).filter(pImage, null); }
private static double bessel(final double t) { if (t == 0.0) { return Math.PI / 4.0; } return besselOrderOne(Math.PI * t) / (2.0 * t); }
case FILTER_POINT: if (input.getType() != BufferedImage.TYPE_CUSTOM) { return fastResample(input, output, width, height, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); return fastResample(input, output, width, height, AffineTransformOp.TYPE_BILINEAR); return fastResample(input, output, width, height, AffineTransformOp.TYPE_BICUBIC); filter = createFilter(filterType); return fastResample(input, output, width, height, AffineTransformOp.TYPE_BILINEAR); result = output != null && temp.getType() != BufferedImage.TYPE_CUSTOM ? /*output*/ ImageUtil.toBuffered(output, temp.getType()) : createCompatibleDestImage(temp, null); resample(temp, result, filter);
static double besselOrderOne(double t) { double p, q; if (t == 0.0) { return 0.0; } p = t; if (t < 0.0) { t = -t; } if (t < 8.0) { return p * j1(t); } q = Math.sqrt(2.0 / (Math.PI * t)) * (p1(t) * (1.0 / Math.sqrt(2.0) * (Math.sin(t) - Math.cos(t))) - 8.0 / t * q1(t) * (-1.0 / Math.sqrt(2.0) * (Math.sin(t) + Math.cos(t)))); if (p < 0.0) { q = -q; } return q; }
System.out.println("to..." + toWidth + "x" + toHeight); publish("Resample..." + toWidth + "x" + toHeight); ResampleOp op = new ResampleOp(toWidth, toHeight); Thread.yield(); op.addProgressListener(new ProgressListener() { public void notifyProgress(float fraction) { int p = (int) (fraction * 100); BufferedImage scaled = op.filter(img, null); pm.close();
ResampleOp resampleOp = new ResampleOp(width, height); BufferedImage rescaledImage = resampleOp.filter(image, null);
ContributorList contribX = calcXContrib(xscale, fwidth, srcWidth, pFilter, xx); weight = bPelDelta ? round(weight) : pel; weight = bPelDelta ? round(weight) : pel; if (weight < 0) { weight = 0;
int height = comp.getHeight () * width / comp.getHeight (); BufferedImage rescaled = new ResampleOp ( width, height ).filter ( image, null );
this(width, height, getFilterType(hints));
static double besselOrderOne(double t) { double p, q; if (t == 0.0) { return 0.0; } p = t; if (t < 0.0) { t = -t; } if (t < 8.0) { return p * j1(t); } q = Math.sqrt(2.0 / (Math.PI * t)) * (p1(t) * (1.0 / Math.sqrt(2.0) * (Math.sin(t) - Math.cos(t))) - 8.0 / t * q1(t) * (-1.0 / Math.sqrt(2.0) * (Math.sin(t) + Math.cos(t)))); if (p < 0.0) { q = -q; } return q; }
int rw = the width I needed; BufferedImage image = ImageIO.read(new File(filename)); ResampleOp resampleOp = new ResampleOp(rw,(rw * image.getHeight()) / image.getWidth() ); resampleOp.setFilter(ResampleFilters.getLanczos3Filter()); image = resampleOp.filter(image, null); File tmpFile = new File(tmpName); ImageIO.write(image, "jpg", tmpFile);
ContributorList contribX = calcXContrib(xscale, fwidth, srcWidth, pFilter, xx); weight = bPelDelta ? round(weight) : pel; weight = bPelDelta ? round(weight) : pel; if (weight < 0) { weight = 0;
this(width, height, getFilterType(hints));
new ResampleOp(image.getWidth() / 10, image.getHeight() / 10, ResampleOp.FILTER_QUADRATIC).filter(image, null); image = new ResampleOp(image.getWidth() / 4, image.getHeight() / 4, ResampleOp.FILTER_QUADRATIC).filter(image, null); long time = System.currentTimeMillis() - start;
return fastResample(pInput, pOutput, mWidth, mHeight, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); case FILTER_TRIANGLE: return fastResample(pInput, pOutput, mWidth, mHeight, AffineTransformOp.TYPE_BILINEAR); case FILTER_QUADRATIC: if (TRANSFORM_OP_BICUBIC_SUPPORT) { return fastResample(pInput, pOutput, mWidth, mHeight, 3); // AffineTransformOp.TYPE_BICUBIC filter = createFilter(mFilterType); return fastResample(pInput, pOutput, mWidth, mHeight, AffineTransformOp.TYPE_BILINEAR); result = pOutput != null ? /*pOutput*/ ImageUtil.toBuffered(pOutput, input.getType()) : createCompatibleDestImage(input, null); resample(input, result, filter);
static double besselOrderOne(double t) { double p, q; if (t == 0.0) { return 0.0; } p = t; if (t < 0.0) { t = -t; } if (t < 8.0) { return p * j1(t); } q = Math.sqrt(2.0 / (Math.PI * t)) * (p1(t) * (1.0 / Math.sqrt(2.0) * (Math.sin(t) - Math.cos(t))) - 8.0 / t * q1(t) * (-1.0 / Math.sqrt(2.0) * (Math.sin(t) + Math.cos(t)))); if (p < 0.0) { q = -q; } return q; }
ContributorList contribX = calcXContrib(xscale, fwidth, srcWidth, pFilter, xx); weight = bPelDelta ? round(weight) : pel; weight = bPelDelta ? round(weight) : pel; if (weight < 0) { weight = 0;
private static double bessel(final double t) { if (t == 0.0) { return Math.PI / 4.0; } return besselOrderOne(Math.PI * t) / (2.0 * t); }
this(pWidth, pHeight, getFilterType(pHints));