本文整理匯總了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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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));
}
示例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;
}
示例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));
}
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}