类java.awt.image.AffineTransformOp源码实例Demo

下面列出了怎么用java.awt.image.AffineTransformOp的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: boubei-tss   文件: Imager.java
public static void zoomImage(String src, Integer maxPicSize) throws Exception {
	File srcFile = new File(src);
	long fileSize = srcFile.length();
	String subfix = FileHelper.getFileSuffix(srcFile.getName());
	List<String> list = Arrays.asList( "jpg,jpeg,bmp,gif".split(",") ); // 这些格式支持有损压缩,png等不支持
	
	if (fileSize <= maxPicSize * 1024 || !list.contains(subfix.toLowerCase()))  { // 文件本身已小于size(K)时,不做缩放
		return;
	}
		
	Double rate = (maxPicSize * 1024.0) / fileSize; // 获取长宽缩放比例
	rate = Math.max(rate, 0.5);

	BufferedImage bufImg = ImageIO.read(srcFile);
	Image Itemp = bufImg.getScaledInstance(bufImg.getWidth(), bufImg.getHeight(), Image.SCALE_SMOOTH);

	AffineTransformOp ato = new AffineTransformOp(AffineTransform.getScaleInstance(rate, rate), null);
	Itemp = ato.filter(bufImg, null);
	
	ImageIO.write((BufferedImage) Itemp, subfix, srcFile);
}
 
源代码2 项目: openjdk-8   文件: OGLDrawImage.java
@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);
}
 
源代码3 项目: r2cloud   文件: Util.java
public static void rotateImage(File result) {
	try {
		BufferedImage image;
		try (FileInputStream fis = new FileInputStream(result)) {
			image = ImageIO.read(fis);
		}
		AffineTransform tx = AffineTransform.getScaleInstance(-1, -1);
		tx.translate(-image.getWidth(null), -image.getHeight(null));
		AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
		image = op.filter(image, null);
		try (FileOutputStream fos = new FileOutputStream(result)) {
			ImageIO.write(image, "jpg", fos);
		}
	} catch (Exception e) {
		LOG.error("unable to rotate image", e);
	}
}
 
源代码4 项目: Bytecoder   文件: DrawImage.java
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 {
            img = op.filter(img, null);
        }
    }
    copyImage(sg, img, x, y, null);
}
 
源代码5 项目: openjdk-jdk8u   文件: D3DDrawImage.java
@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);
}
 
源代码6 项目: openjdk-8-source   文件: DrawImage.java
public static boolean isSimpleTranslate(SunGraphics2D sg) {
    int ts = sg.transformState;
    if (ts <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
        // Integer translates are always "simple"
        return true;
    }
    if (ts >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
        // Scales and beyond are always "not simple"
        return false;
    }
    // non-integer translates are only simple when not interpolating
    if (sg.interpolationType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR) {
        return true;
    }
    return false;
}
 
源代码7 项目: jdk8u-jdk   文件: D3DDrawImage.java
@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);
}
 
源代码8 项目: jdk8u-jdk   文件: DrawImage.java
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 {
            img = op.filter(img, null);
        }
    }
    copyImage(sg, img, x, y, null);
}
 
源代码9 项目: hottub   文件: D3DDrawImage.java
@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);
}
 
/**
 * Some quick and dirty image scaling - please note that for best performance
 * and quality you should use image rescaling libraries.
 */
@Override
public BufferedImage resample(BufferedImage bufferedImage, int width, int height) {

    Dimension imageDimension = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight());
    Dimension boundaryDimension = new Dimension(width, height);
    Dimension scaledDimension = BufferedImageUtils.getScaledDimension(imageDimension, boundaryDimension);

    double scaleX = scaledDimension.getWidth() / bufferedImage.getWidth();
    double scaleY = scaledDimension.getHeight() / bufferedImage.getHeight();

    AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
    AffineTransformOp biLinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);

    return biLinearScaleOp.filter(
            bufferedImage,
            new BufferedImage(scaledDimension.width, scaledDimension.height, bufferedImage.getType()));
}
 
源代码11 项目: jdk8u60   文件: DrawImage.java
public static boolean isSimpleTranslate(SunGraphics2D sg) {
    int ts = sg.transformState;
    if (ts <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
        // Integer translates are always "simple"
        return true;
    }
    if (ts >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
        // Scales and beyond are always "not simple"
        return false;
    }
    // non-integer translates are only simple when not interpolating
    if (sg.interpolationType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR) {
        return true;
    }
    return false;
}
 
源代码12 项目: openjdk-jdk9   文件: D3DBlitLoops.java
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    D3DBlitLoops.Blit(src, dst,
                      comp, clip, null,
                      AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                      sx, sy, sx+w, sy+h,
                      dx, dy, dx+w, dy+h,
                      typeval, false);
}
 
源代码13 项目: openjdk-jdk9   文件: D3DBlitLoops.java
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    D3DBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, null,
                         AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                         sx, sy, sx+w, sy+h,
                         dx, dy, dx+w, dy+h,
                         true);
}
 
源代码14 项目: openjdk-jdk8u   文件: D3DBlitLoops.java
public void Scale(SurfaceData src, SurfaceData dst,
                  Composite comp, Region clip,
                  int sx1, int sy1,
                  int sx2, int sy2,
                  double dx1, double dy1,
                  double dx2, double dy2)
{
    D3DBlitLoops.Blit(src, dst,
                      comp, clip, null,
                      AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                      sx1, sy1, sx2, sy2,
                      dx1, dy1, dx2, dy2,
                      typeval, false);
}
 
源代码15 项目: hottub   文件: SunGraphics2D.java
public SunGraphics2D(SurfaceData sd, Color fg, Color bg, Font f) {
    surfaceData = sd;
    foregroundColor = fg;
    backgroundColor = bg;

    transform = new AffineTransform();
    stroke = defaultStroke;
    composite = defaultComposite;
    paint = foregroundColor;

    imageComp = CompositeType.SrcOverNoEa;

    renderHint = SunHints.INTVAL_RENDER_DEFAULT;
    antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
    textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT;
    fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF;
    lcdTextContrast = lcdTextContrastDefaultValue;
    interpolationHint = -1;
    strokeHint = SunHints.INTVAL_STROKE_DEFAULT;
    resolutionVariantHint = SunHints.INTVAL_RESOLUTION_VARIANT_DEFAULT;

    interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR;

    validateColor();

    devScale = sd.getDefaultScale();
    if (devScale != 1) {
        transform.setToScale(devScale, devScale);
        invalidateTransform();
    }

    font = f;
    if (font == null) {
        font = defaultFont;
    }

    setDevClip(sd.getBounds());
    invalidatePipe();
}
 
源代码16 项目: hottub   文件: D3DBlitLoops.java
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    D3DBlitLoops.Blit(src, dst,
                      comp, clip, null,
                      AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                      sx, sy, sx+w, sy+h,
                      dx, dy, dx+w, dy+h,
                      typeval, true);
}
 
源代码17 项目: dragonwell8_jdk   文件: OGLBlitLoops.java
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    OGLBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, null,
                         AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                         sx, sy, sx+w, sy+h,
                         dx, dy, dx+w, dy+h,
                         false);
}
 
源代码18 项目: openjdk-jdk8u   文件: SunGraphics2D.java
/**
 * Sets the preferences for the rendering algorithms.
 * Hint categories include controls for rendering quality and
 * overall time/quality trade-off in the rendering process.
 * @param hints The rendering hints to be set
 * @see RenderingHints
 */
public void setRenderingHints(Map<?,?> hints) {
    this.hints = null;
    renderHint = SunHints.INTVAL_RENDER_DEFAULT;
    antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
    textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT;
    fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF;
    lcdTextContrast = lcdTextContrastDefaultValue;
    interpolationHint = -1;
    interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR;
    boolean customHintPresent = false;
    Iterator<?> iter = hints.keySet().iterator();
    while (iter.hasNext()) {
        Object key = iter.next();
        if (key == SunHints.KEY_RENDERING ||
            key == SunHints.KEY_ANTIALIASING ||
            key == SunHints.KEY_TEXT_ANTIALIASING ||
            key == SunHints.KEY_FRACTIONALMETRICS ||
            key == SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST ||
            key == SunHints.KEY_STROKE_CONTROL ||
            key == SunHints.KEY_INTERPOLATION)
        {
            setRenderingHint((Key) key, hints.get(key));
        } else {
            customHintPresent = true;
        }
    }
    if (customHintPresent) {
        this.hints = makeHints(hints);
    }
    invalidatePipe();
}
 
源代码19 项目: dragonwell8_jdk   文件: OGLBlitLoops.java
public void Scale(SurfaceData src, SurfaceData dst,
                  Composite comp, Region clip,
                  int sx1, int sy1,
                  int sx2, int sy2,
                  double dx1, double dy1,
                  double dx2, double dy2)
{
    OGLBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, null,
                         AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                         sx1, sy1, sx2, sy2,
                         dx1, dy1, dx2, dy2,
                         true);
}
 
源代码20 项目: jdk8u-jdk   文件: D3DDrawImage.java
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
                                AffineTransform tx, int interpType,
                                int sx1, int sy1, int sx2, int sy2,
                                Color bgColor)
{
    // punt to the MediaLib-based transformImage() in the superclass if:
    //     - bicubic interpolation is specified
    //     - a background color is specified and will be used
    //     - an appropriate TransformBlit primitive could not be found
    if (interpType != AffineTransformOp.TYPE_BICUBIC) {
        SurfaceData dstData = sg.surfaceData;
        SurfaceData srcData =
            dstData.getSourceSurfaceData(img,
                                         sg.TRANSFORM_GENERIC,
                                         sg.imageComp,
                                         bgColor);

        if (srcData != null && !isBgOperation(srcData, bgColor)) {
            SurfaceType srcType = srcData.getSurfaceType();
            SurfaceType dstType = dstData.getSurfaceType();
            TransformBlit blit = TransformBlit.getFromCache(srcType,
                                                            sg.imageComp,
                                                            dstType);

            if (blit != null) {
                blit.Transform(srcData, dstData,
                               sg.composite, sg.getCompClip(),
                               tx, interpType,
                               sx1, sy1, 0, 0, sx2-sx1, sy2-sy1);
                return;
            }
        }
    }

    super.renderImageXform(sg, img, tx, interpType,
                           sx1, sy1, sx2, sy2, bgColor);
}
 
源代码21 项目: openjdk-8   文件: SunGraphics2D.java
public SunGraphics2D(SurfaceData sd, Color fg, Color bg, Font f) {
    surfaceData = sd;
    foregroundColor = fg;
    backgroundColor = bg;

    transform = new AffineTransform();
    stroke = defaultStroke;
    composite = defaultComposite;
    paint = foregroundColor;

    imageComp = CompositeType.SrcOverNoEa;

    renderHint = SunHints.INTVAL_RENDER_DEFAULT;
    antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
    textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT;
    fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF;
    lcdTextContrast = lcdTextContrastDefaultValue;
    interpolationHint = -1;
    strokeHint = SunHints.INTVAL_STROKE_DEFAULT;

    interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR;

    validateColor();

    devScale = sd.getDefaultScale();
    if (devScale != 1) {
        transform.setToScale(devScale, devScale);
        invalidateTransform();
    }

    font = f;
    if (font == null) {
        font = defaultFont;
    }

    setDevClip(sd.getBounds());
    invalidatePipe();
}
 
源代码22 项目: jdk8u60   文件: D3DBlitLoops.java
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    D3DBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, null,
                         AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                         sx, sy, sx+w, sy+h,
                         dx, dy, dx+w, dy+h,
                         true);
}
 
源代码23 项目: openjdk-8   文件: OGLBlitLoops.java
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    OGLBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, null,
                         AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                         sx, sy, sx+w, sy+h,
                         dx, dy, dx+w, dy+h,
                         true);
}
 
源代码24 项目: hottub   文件: D3DBlitLoops.java
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    D3DBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, null,
                         AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                         sx, sy, sx+w, sy+h,
                         dx, dy, dx+w, dy+h,
                         true);
}
 
源代码25 项目: hottub   文件: D3DBlitLoops.java
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    D3DBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, null,
                         AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                         sx, sy, sx+w, sy+h,
                         dx, dy, dx+w, dy+h,
                         true);
}
 
源代码26 项目: openjdk-jdk8u   文件: OGLBlitLoops.java
public void Scale(SurfaceData src, SurfaceData dst,
                  Composite comp, Region clip,
                  int sx1, int sy1,
                  int sx2, int sy2,
                  double dx1, double dy1,
                  double dx2, double dy2)
{
    OGLBlitLoops.Blit(src, dst,
                      comp, clip, null,
                      AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                      sx1, sy1, sx2, sy2,
                      dx1, dy1, dx2, dy2,
                      typeval, false);
}
 
源代码27 项目: maze-harvester   文件: ImageFieldMask.java
/** Returns a mask with the same image, resized to (w,h). */
public ImageFieldMask scaleTo(Dimension size) {
  int w = size.width;
  int h = size.height;
  BufferedImage grayImage = this.image;
  BufferedImage scaledImage = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
  AffineTransform at = new AffineTransform();
  at.scale(((double)w) / grayImage.getWidth(), ((double) h) / grayImage.getHeight());
  AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
  scaleOp.filter(grayImage, scaledImage);
  return new ImageFieldMask(scaledImage);
}
 
源代码28 项目: dragonwell8_jdk   文件: D3DBlitLoops.java
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    D3DBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, null,
                         AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                         sx, sy, sx+w, sy+h,
                         dx, dy, dx+w, dy+h,
                         true);
}
 
源代码29 项目: jdk8u-jdk   文件: D3DBlitLoops.java
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    D3DBlitLoops.Blit(src, dst,
                      comp, clip, null,
                      AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                      sx, sy, sx+w, sy+h,
                      dx, dy, dx+w, dy+h,
                      typeval, true);
}
 
源代码30 项目: jdk8u60   文件: D3DBlitLoops.java
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    D3DBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, null,
                         AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                         sx, sy, sx+w, sy+h,
                         dx, dy, dx+w, dy+h,
                         false);
}
 
 类所在包
 同包方法