当前位置: 首页>>代码示例>>Java>>正文


Java AffineTransformOp类代码示例

本文整理汇总了Java中java.awt.image.AffineTransformOp的典型用法代码示例。如果您正苦于以下问题:Java AffineTransformOp类的具体用法?Java AffineTransformOp怎么用?Java AffineTransformOp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AffineTransformOp类属于java.awt.image包,在下文中一共展示了AffineTransformOp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transformImage

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
@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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:D3DDrawImage.java

示例2: generateIdenticon

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
/**
 * Code taken from: <a href="https://stackoverflow.com/a/40699460">Stackoverflow answer from Kevin G. based on code from davidhampgonsalves.com/Identicons</a>
 * Comments and slight modifications added.
 */
public static javafx.scene.image.Image generateIdenticon(String text, int image_width, int image_height) throws IOException {
	// If the input name/text is null or empty no image can be created.
	if (text == null || text.length() < 3) {
		return null;
	}

	int width = 5, height = 5;

	byte[] hash = text.getBytes();

	BufferedImage identicon = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
	WritableRaster raster = identicon.getRaster();

	int [] background = new int [] {255,255,255, 0};
	int [] foreground = new int [] {hash[0] & 255, hash[1] & 255, hash[2] & 255, 255};

	for(int x=0 ; x < width ; x++) {
		//Enforce horizontal symmetry
		int i = x < 3 ? x : 4 - x;
		for(int y=0 ; y < height; y++) {
			int [] pixelColor;
			//toggle pixels based on bit being on/off
			if((hash[i] >> y & 1) == 1)
				pixelColor = foreground;
			else
				pixelColor = background;
			raster.setPixel(x, y, pixelColor);
		}
	}

	BufferedImage finalImage = new BufferedImage(image_width, image_height, BufferedImage.TYPE_INT_ARGB);

	//Scale image to the size you want
	AffineTransform at = new AffineTransform();
	at.scale(image_width / width, image_height / height);
	AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
	finalImage = op.filter(identicon, finalImage);

	// Convert BufferedImage to javafx image
	return createImage(finalImage);
}
 
开发者ID:Gurgy,项目名称:Cypher,代码行数:46,代码来源:Util.java

示例3: isSimpleTranslate

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:DrawImage.java

示例4: transformImage

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:DrawImage.java

示例5: transformImage

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
@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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:OGLDrawImage.java

示例6: girar

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
/**
 * Rotaciona uma imagem
 *
 * @param image imagem a ser rotacionada
 * @param angle ângulo da rotação
 * @return imagem rotacionada
 */
public static ImageIcon girar(ImageIcon image, double angle) {
    BufferedImage rotateImage = ImageIconToBufferedImage(image);
    angle %= 360;
    if (angle < 0) {
        angle += 360;
    }
    AffineTransform tx = new AffineTransform();
    tx.rotate(Math.toRadians(angle), rotateImage.getWidth() / 2.0, rotateImage.getHeight() / 2.0);

    double ytrans;
    double xtrans;
    if (angle <= 90) {
        xtrans = tx.transform(new Point2D.Double(0, rotateImage.getHeight()), null).getX();
        ytrans = tx.transform(new Point2D.Double(0.0, 0.0), null).getY();
    } else if (angle <= 180) {
        xtrans = tx.transform(new Point2D.Double(rotateImage.getWidth(), rotateImage.getHeight()), null).getX();
        ytrans = tx.transform(new Point2D.Double(0, rotateImage.getHeight()), null).getY();
    } else if (angle <= 270) {
        xtrans = tx.transform(new Point2D.Double(rotateImage.getWidth(), 0), null).getX();
        ytrans = tx.transform(new Point2D.Double(rotateImage.getWidth(), rotateImage.getHeight()), null).getY();
    } else {
        xtrans = tx.transform(new Point2D.Double(0, 0), null).getX();
        ytrans = tx.transform(new Point2D.Double(rotateImage.getWidth(), 0), null).getY();
    }

    AffineTransform translationTransform = new AffineTransform();
    translationTransform.translate(-xtrans, -ytrans);
    tx.preConcatenate(translationTransform);

    return new ImageIcon(new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR).filter(rotateImage, null));
}
 
开发者ID:limagiran,项目名称:hearthstone,代码行数:39,代码来源:Img.java

示例7: run

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
@Override
public BufferedImage run(final @NonNull BufferedImage image) {
    if (isFlippedHorizontally || isFlippedVertically) {
        final double scaleX = isFlippedHorizontally ? -1 : 1;
        final double scaleY = isFlippedVertically ? -1 : 1;
        final double translateX = isFlippedHorizontally ? -image.getWidth() : 0;
        final double translateY = isFlippedVertically ? -image.getHeight() : 0;

        final AffineTransform tx = AffineTransform.getScaleInstance(scaleX, scaleY);
        tx.translate(translateX, translateY);

        final BufferedImageOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
        return op.filter(image, null);
    }

    return image;
}
 
开发者ID:Valkryst,项目名称:VTerminal,代码行数:18,代码来源:FlipShader.java

示例8: Font

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
/**
 * Constructs a new Font.
 *
 * @param characterImages
 *        The base character images.
 *
 * @param scale
 *        The amount to scale each character image by.
 *
 * @throws NullPointerException
 *         If the characterImages is null.
 *
 * @throws IOException
 *         If an I/O error occurs.
 */
public Font(final @NonNull HashMap<Character, BufferedImage> characterImages, final int scale) throws IOException {
    this.characterImages = characterImages;

    final int width = characterImages.get('X').getWidth() * scale;
    final int height = characterImages.get('X').getHeight() * scale;
    dimensions = new Dimension(width, height);

    if (scale > 0) {
        final AffineTransform tx = AffineTransform.getScaleInstance(scale, scale);
        final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);

        for (final Map.Entry<Character, BufferedImage> entry : characterImages.entrySet()) {
            characterImages.put(entry.getKey(), op.filter(entry.getValue(), null));
        }
    }
}
 
开发者ID:Valkryst,项目名称:VTerminal,代码行数:32,代码来源:Font.java

示例9: applyTransformations

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
/**
 * Flips and scales the image.
 *
 * @return
 *         The flipped and scaled image.
 */
private BufferedImage applyTransformations() {
    final AffineTransform tx;

    if (flipHorizontally && flipVertically) {
        tx = AffineTransform.getScaleInstance(-scaleX, -scaleY);
        tx.translate(-image.getWidth(), -image.getHeight());
    } else if (flipHorizontally) {
        tx = AffineTransform.getScaleInstance(-scaleX, scaleY);
        tx.translate(-image.getWidth(), 0);
    } else if(flipVertically) {
        tx = AffineTransform.getScaleInstance(scaleX, -scaleY);
        tx.translate(0, -image.getHeight());
    } else {
        tx = AffineTransform.getScaleInstance(scaleX, scaleY);
    }

    final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    return op.filter(image, null);
}
 
开发者ID:Valkryst,项目名称:VTerminal,代码行数:26,代码来源:ImagePrinter.java

示例10: addShadow

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
/**
 * 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;
  }

  // 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(image.getWidth(), image.getHeight() + rotatedImage.getHeight());
  final Graphics2D g2D = shadow.createGraphics();
  g2D.drawImage(rotatedImage, xOffset, yOffset, null);
  g2D.drawImage(image, 0, 0, null);

  g2D.dispose();

  return shadow;
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:42,代码来源:ImageProcessing.java

示例11: Blit

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:D3DBlitLoops.java

示例12: scale

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
/**
 * Build a scaled version of an image.
 *
 * @param img   image to scale
 * @param ratio scaling ratio
 * @return the scaled image
 */
public static BufferedImage scale (BufferedImage img,
                                   double ratio)
{
    AffineTransform at = AffineTransform.getScaleInstance(ratio, ratio);
    AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
    BufferedImage scaledImg = new BufferedImage(
            (int) Math.ceil(img.getWidth() * ratio),
            (int) Math.ceil(img.getHeight() * ratio),
            img.getType());

    return atop.filter(img, scaledImg);
}
 
开发者ID:Audiveris,项目名称:omr-dataset-tools,代码行数:20,代码来源:SheetProcessor.java

示例13: slant

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
public static BufferedImage slant(BufferedImage image, FlexQuadrilateral quadrilateral, int xTranslation) {
    Point p = new Point(quadrilateral.getBottomLeft().x, quadrilateral.getTopLeft().y);
    double theta = Geometry.theta(quadrilateral.getBottomLeft(), p, quadrilateral.getTopLeft());

    AffineTransform transform = AffineTransform.getTranslateInstance(xTranslation, 0);
    transform.shear(Math.tan(theta), 0);

    transform.translate(xTranslation, 0);
    AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
    return op.filter(image, null);
}
 
开发者ID:defano,项目名称:jmonet,代码行数:12,代码来源:Transform.java

示例14: affineTransform

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
public void affineTransform (double fShxFactor, double fShyFactor) {

        try {
          AffineTransform shearer =
            AffineTransform.getShearInstance (fShxFactor, fShyFactor);
          AffineTransformOp shear_op =
            new AffineTransformOp (shearer, null);
          bufferedImage = shear_op.filter (bufferedImage, null);
        }
        catch (Exception e) {
          System.out.println("Shearing exception = " + e);
        }
      }
 
开发者ID:ZiryLee,项目名称:FileUpload2Spring,代码行数:14,代码来源:EasyImage.java

示例15: Blit

import java.awt.image.AffineTransformOp; //导入依赖的package包/类
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    OGLBlitLoops.Blit(src, dst,
                      comp, clip, null,
                      AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                      sx, sy, sx+w, sy+h,
                      dx, dy, dx+w, dy+h,
                      typeval, true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:OGLBlitLoops.java


注:本文中的java.awt.image.AffineTransformOp类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。