java.awt.image

Class AffineTransformOp

Implemented Interfaces:
BufferedImageOp, RasterOp

public class AffineTransformOp
extends Object
implements BufferedImageOp, RasterOp

This class uses an affine transform to perform a linear mapping from 2D coordinates in the source image or Raster to 2D coordinates in the destination image or Raster. The type of interpolation that is used is specified through a constructor, either by a RenderingHints object or by one of the integer interpolation types defined in this class.

If a RenderingHints object is specified in the constructor, the interpolation hint and the rendering quality hint are used to set the interpolation type for this operation. The color rendering hint and the dithering hint can be used when color conversion is required.

Note that the following constraints have to be met:

See Also:
AffineTransform, BufferedImageFilter, RenderingHints.KEY_INTERPOLATION, RenderingHints.KEY_RENDERING, RenderingHints.KEY_COLOR_RENDERING, RenderingHints.KEY_DITHERING

Field Summary

static int
TYPE_BICUBIC
Bicubic interpolation type.
static int
TYPE_BILINEAR
Bilinear interpolation type.
static int
TYPE_NEAREST_NEIGHBOR
Nearest-neighbor interpolation type.

Constructor Summary

AffineTransformOp(AffineTransform xform, int interpolationType)
Constructs an AffineTransformOp given an affine transform and the interpolation type.
AffineTransformOp(AffineTransform xform, RenderingHints hints)
Constructs an AffineTransformOp given an affine transform.

Method Summary

BufferedImage
createCompatibleDestImage(BufferedImage src, ColorModel destCM)
Creates a zeroed destination image with the correct size and number of bands.
WritableRaster
createCompatibleDestRaster(Raster src)
Creates a zeroed destination Raster with the correct size and number of bands.
BufferedImage
filter(BufferedImage src, BufferedImage dst)
Transforms the source BufferedImage and stores the results in the destination BufferedImage.
WritableRaster
filter(Raster src, WritableRaster dst)
Transforms the source Raster and stores the results in the destination Raster.
Rectangle2D
getBounds2D(BufferedImage src)
Returns the bounding box of the transformed destination.
Rectangle2D
getBounds2D(Raster src)
Returns the bounding box of the transformed destination.
int
getInterpolationType()
Returns the interpolation type used by this op.
Point2D
getPoint2D(Point2D srcPt, Point2D dstPt)
Returns the location of the corresponding destination point given a point in the source.
RenderingHints
getRenderingHints()
Returns the rendering hints used by this transform operation.
AffineTransform
getTransform()
Returns the affine transform used by this transform operation.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

TYPE_BICUBIC

public static final int TYPE_BICUBIC
Bicubic interpolation type.
Field Value:
3

TYPE_BILINEAR

public static final int TYPE_BILINEAR
Bilinear interpolation type.
Field Value:
2
Usages and Demos :

View More Examples of AffineTransformOp.TYPE_BILINEAR
   1:     AffineTransformOp res = new AffineTransformOp(AffineTransform.getScaleInstance(sx, sy),
   2:         AffineTransformOp.TYPE_BILINEAR);
   3:     BufferedImage r = new BufferedImage(_w, _h, BufferedImage.TYPE_3BYTE_BGR);
   4:     res.filter(_init, r);
   5:     return r;

View Full Code Here
   1:                 biop = new AffineTransformOp(at,
   2:                                              AffineTransformOp.TYPE_BILINEAR);
   3:                 break;
   4:         ...
   5:                 biop = new AffineTransformOp(at,
   6:                                              AffineTransformOp.TYPE_BILINEAR);
   7:             }
   8:             g2.drawImage(bimg,biop,x,y); 
   9:             TextLayout tl = new TextLayout(theDesc[i], g2.getFont(),g2.getFontRenderContext());

View Full Code Here
   1:         0.0f,  -0.75f, 0.0f})),
   2:     new AffineTransformOp(mirrorTransform,AffineTransformOp.TYPE_BILINEAR),
   3:     new AffineTransformOp(AffineTransform.getRotateInstance(Math.PI,64,95),
   4:                   AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
   5:     new AffineTransformOp(AffineTransform.getRotateInstance(Math.PI/12,

View Full Code Here
   1:         0.0f,  -0.75f, 0.0f})),
   2:     new AffineTransformOp(mirrorTransform,AffineTransformOp.TYPE_BILINEAR),
   3:     new AffineTransformOp(AffineTransform.getRotateInstance(Math.PI,64,95),
   4:                   AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
   5:     new AffineTransformOp(AffineTransform.getRotateInstance(Math.PI/12,

View Full Code Here
   1:                AffineTransformOp op  = new AffineTransformOp(transform,
   2:                   AffineTransformOp.TYPE_BILINEAR);
   3:                filter(op);
   4:             }
   5:          });

View Full Code Here

TYPE_NEAREST_NEIGHBOR

public static final int TYPE_NEAREST_NEIGHBOR
Nearest-neighbor interpolation type.
Field Value:
1
Usages and Demos :

View More Examples of AffineTransformOp.TYPE_NEAREST_NEIGHBOR
   1:             AffineTransformOp op = new AffineTransformOp(tx,
   2:                 AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
   3:             img = op.filter(img, null);
   4:         }
   5:         catch(IOException e) {

View Full Code Here
   1:                 biop = new AffineTransformOp(at,
   2:                                              AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
   3:                 break;
   4:             case 2 : x = 5; y = h/2+15;
   5:                 byte chlut[] = new byte[256]; 

View Full Code Here
   1:     new AffineTransformOp(AffineTransform.getRotateInstance(Math.PI,64,95),
   2:                   AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
   3:     new AffineTransformOp(AffineTransform.getRotateInstance(Math.PI/12,
   4:         ...
   5:                                 0, 190),
   6:                   AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
   7:     };

View Full Code Here
   1:     new AffineTransformOp(AffineTransform.getRotateInstance(Math.PI,64,95),
   2:                   AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
   3:     new AffineTransformOp(AffineTransform.getRotateInstance(Math.PI/12,
   4:         ...
   5:                                 0, 190),
   6:                   AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
   7:     };

View Full Code Here
   1:       AffineTransform at = AffineTransform.getScaleInstance(ratio, ratio);
   2:       AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
   3:       thumbnailImage = op.filter(thumbnailImage, null);
   4:         ...
   5:       at.scale(ratio, ratio);
   6:       AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
   7:       BufferedImage scaledImage = op.filter(originalImage, null);
   8:         ...
   9:       at.translate(-(scaledImage.getWidth() / 2), -(scaledImage.getHeight() / 2));
  10:       op = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
  11:       BufferedImage thumbnailImage = op.filter(scaledImage, null);

View Full Code Here

Constructor Details

AffineTransformOp

public AffineTransformOp(AffineTransform xform,
                         int interpolationType)
Constructs an AffineTransformOp given an affine transform and the interpolation type.
Parameters:
xform - The AffineTransform to use for the operation.
interpolationType - One of the integer interpolation type constants defined by this class: TYPE_NEAREST_NEIGHBOR, TYPE_BILINEAR, TYPE_BICUBIC.
Throws:
ImagingOpException - if the transform is non-invertible.
Usages and Demos :

View More Examples of AffineTransformOp(AffineTransform xform,int interpolationType)
   1:       BufferedImage Bi = ImageIO.read(F);
   2:       AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(Ratio, Ratio), null);
   3:       Image Itemp = op.filter(Bi, null);
   4: 
   5:       File ThF = new File(newpicture.getImgDir(),newpicture.getImgfile());

View Full Code Here
   1:         BufferedImage Bi = ImageIO.read(F);
   2:         AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(Ratio, Ratio), null);
   3:         Image Itemp = op.filter(Bi, null);
   4: 
   5:         if (isJpg(imgfile)){

View Full Code Here
   1:                                             (double)height / src.getHeight());
   2:         AffineTransformOp scale = new AffineTransformOp(tf, AffineTransformOp.TYPE_BILINEAR);
   3:         BufferedImage dst = scale.filter(src,null);
   4:         return new ImageComponent2D(ImageComponent2D.FORMAT_RGB, dst,true,true);
   5:     }

View Full Code Here
   1:          }
   2:          AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_BILINEAR);
   3:          g2d.drawImage(source, op, x, y);
   4:       }
   5:       return result;

View Full Code Here
   1: 
   2:         AffineTransformOp op = new AffineTransformOp(aff, hints);
   3: 
   4:         BufferedImage srcBI, myBI;
   5:         ColorModel srcCM = src.getColorModel();

View Full Code Here

AffineTransformOp

public AffineTransformOp(AffineTransform xform,
                         RenderingHints hints)
Constructs an AffineTransformOp given an affine transform. The interpolation type is determined from the RenderingHints object. If the interpolation hint is defined, it will be used. Otherwise, if the rendering quality hint is defined, the interpolation type is determined from its value. If no hints are specified (hints is null), the interpolation type is TYPE_NEAREST_NEIGHBOR.
Parameters:
xform - The AffineTransform to use for the operation.
hints - The RenderingHints object used to specify the interpolation type for the operation.
Throws:
ImagingOpException - if the transform is non-invertible.
Usages and Demos :

View More Examples of AffineTransformOp(AffineTransform xform,RenderingHints hints)
   1:       BufferedImage Bi = ImageIO.read(F);
   2:       AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(Ratio, Ratio), null);
   3:       Image Itemp = op.filter(Bi, null);
   4: 
   5:       File ThF = new File(newpicture.getImgDir(),newpicture.getImgfile());

View Full Code Here
   1:         BufferedImage Bi = ImageIO.read(F);
   2:         AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(Ratio, Ratio), null);
   3:         Image Itemp = op.filter(Bi, null);
   4: 
   5:         if (isJpg(imgfile)){

View Full Code Here
   1:                                             (double)height / src.getHeight());
   2:         AffineTransformOp scale = new AffineTransformOp(tf, AffineTransformOp.TYPE_BILINEAR);
   3:         BufferedImage dst = scale.filter(src,null);
   4:         return new ImageComponent2D(ImageComponent2D.FORMAT_RGB, dst,true,true);
   5:     }

View Full Code Here
   1:          }
   2:          AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_BILINEAR);
   3:          g2d.drawImage(source, op, x, y);
   4:       }
   5:       return result;

View Full Code Here
   1: 
   2:         AffineTransformOp op = new AffineTransformOp(aff, hints);
   3: 
   4:         BufferedImage srcBI, myBI;
   5:         ColorModel srcCM = src.getColorModel();

View Full Code Here

Method Details

createCompatibleDestImage

public BufferedImage createCompatibleDestImage(BufferedImage src,
                                               ColorModel destCM)
Creates a zeroed destination image with the correct size and number of bands. A RasterFormatException may be thrown if the transformed width or height is equal to 0.

If destCM is null, an appropriate ColorModel is used; this ColorModel may have an alpha channel even if the source ColorModel is opaque.

Specified by:
createCompatibleDestImage in interface BufferedImageOp
Parameters:
src - The BufferedImage to be transformed.
destCM - ColorModel of the destination. If null, an appropriate ColorModel is used.
Returns:
The zeroed destination image.
Usages and Demos :

View More Examples of createCompatibleDestImage(BufferedImage src,ColorModel destCM)
   1: import java.awt.geom.Rectangle2D;
   2: import java.awt.image.AffineTransformOp;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5:                         dsize / img.getHeight());
   6:                 AffineTransformOp ato = new AffineTransformOp(scaleTx,
   7:                         AffineTransformOp.TYPE_BILINEAR);
   8:         ...
   9:                 BufferedImage scaledImage = ato.createCompatibleDestImage(img, img.getColorModel());
  10:                 img = ato.filter(img, scaledImage);
  11:         ...
  12:             AffineTransformOp ato = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
  13:             BufferedImage scaledImage = ato.createCompatibleDestImage(image, image.getColorModel());

View Full Code Here

createCompatibleDestRaster

public WritableRaster createCompatibleDestRaster(Raster src)
Creates a zeroed destination Raster with the correct size and number of bands. A RasterFormatException may be thrown if the transformed width or height is equal to 0.
Specified by:
createCompatibleDestRaster in interface RasterOp
Parameters:
src - The Raster to be transformed.
Returns:
The zeroed destination Raster.

filter

public final BufferedImage filter(BufferedImage src,
                                  BufferedImage dst)
Transforms the source BufferedImage and stores the results in the destination BufferedImage. If the color models for the two images do not match, a color conversion into the destination color model is performed. If the destination image is null, a BufferedImage is created with the source ColorModel.

The coordinates of the rectangle returned by getBounds2D(BufferedImage) are not necessarily the same as the coordinates of the BufferedImage returned by this method. If the upper-left corner coordinates of the rectangle are negative then this part of the rectangle is not drawn. If the upper-left corner coordinates of the rectangle are positive then the filtered image is drawn at that position in the destination BufferedImage.

An IllegalArgumentException is thrown if the source is the same as the destination.

Specified by:
filter in interface BufferedImageOp
Parameters:
src - The BufferedImage to transform.
dst - The BufferedImage in which to store the results of the transformation.
Returns:
The filtered BufferedImage.
Throws:
IllegalArgumentException - if src and dst are the same
ImagingOpException - if the image cannot be transformed because of a data-processing error that might be caused by an invalid image format, tile format, or image-processing operation, or any other unsupported operation.
Usages and Demos :

View More Examples of filter(BufferedImage src,BufferedImage dst)
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.image.AffineTransformOp;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5:     double sy = (double) _h / ((double) _init.getHeight());
   6:     AffineTransformOp res = new AffineTransformOp(AffineTransform.getScaleInstance(sx, sy),
   7:         AffineTransformOp.TYPE_BILINEAR);
   8:         ...
   9:     BufferedImage r = new BufferedImage(_w, _h, BufferedImage.TYPE_3BYTE_BGR);
  10:     res.filter(_init, r);
  11:     return r;

View Full Code Here
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.image.AffineTransformOp;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5:             tx.translate(0, -img.getHeight(null));
   6:             AffineTransformOp op = new AffineTransformOp(tx,
   7:                 AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
   8:         ...
   9:             img = op.filter(img, null);
  10:         }

View Full Code Here
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.image.AffineTransformOp;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5:       BufferedImageOp op = getGamma(value);
   6:       return op.filter(source, dest);
   7:    }
   8:         ...
   9:          }
  10:          AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_BILINEAR);
  11:          g2d.drawImage(source, op, x, y);

View Full Code Here
   1: import java.awt.geom.Point2D;
   2: import java.awt.image.AffineTransformOp;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5: 
   6:         AffineTransformOp op = new AffineTransformOp(aff, hints);
   7: 
   8:         ...
   9: 
  10:         op.filter(srcBI, myBI);

View Full Code Here
   1:     Current = new BufferedImage(wide, high ,BufferedImage.TYPE_INT_ARGB);
   2:     AffineTransformOp scale = new AffineTransformOp(trans, Quality);
   3:         ...
   4:     scale.filter(Original, Current);
   5:     updateBoundingBox();
   6:         ...
   7:     SCurrent = new BufferedImage(wide, high, BufferedImage.TYPE_INT_ARGB);
   8:     scale.filter(Selected, SCurrent);
   9:   }

View Full Code Here

filter

public final WritableRaster filter(Raster src,
                                   WritableRaster dst)
Transforms the source Raster and stores the results in the destination Raster. This operation performs the transform band by band.

If the destination Raster is null, a new Raster is created. An IllegalArgumentException may be thrown if the source is the same as the destination or if the number of bands in the source is not equal to the number of bands in the destination.

The coordinates of the rectangle returned by getBounds2D(Raster) are not necessarily the same as the coordinates of the WritableRaster returned by this method. If the upper-left corner coordinates of rectangle are negative then this part of the rectangle is not drawn. If the coordinates of the rectangle are positive then the filtered image is drawn at that position in the destination Raster.

Specified by:
filter in interface RasterOp
Parameters:
src - The Raster to transform.
dst - The Raster in which to store the results of the transformation.
Returns:
The transformed Raster.
Throws:
ImagingOpException - if the raster cannot be transformed because of a data-processing error that might be caused by an invalid image format, tile format, or image-processing operation, or any other unsupported operation.
Usages and Demos :

View More Examples of filter(Raster src,WritableRaster dst)
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.image.AffineTransformOp;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5:     double sy = (double) _h / ((double) _init.getHeight());
   6:     AffineTransformOp res = new AffineTransformOp(AffineTransform.getScaleInstance(sx, sy),
   7:         AffineTransformOp.TYPE_BILINEAR);
   8:         ...
   9:     BufferedImage r = new BufferedImage(_w, _h, BufferedImage.TYPE_3BYTE_BGR);
  10:     res.filter(_init, r);
  11:     return r;

View Full Code Here
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.image.AffineTransformOp;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5:             tx.translate(0, -img.getHeight(null));
   6:             AffineTransformOp op = new AffineTransformOp(tx,
   7:                 AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
   8:         ...
   9:             img = op.filter(img, null);
  10:         }

View Full Code Here
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.image.AffineTransformOp;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5:       BufferedImageOp op = getGamma(value);
   6:       return op.filter(source, dest);
   7:    }
   8:         ...
   9:          }
  10:          AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_BILINEAR);
  11:          g2d.drawImage(source, op, x, y);

View Full Code Here
   1: import java.awt.geom.Point2D;
   2: import java.awt.image.AffineTransformOp;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5: 
   6:         AffineTransformOp op = new AffineTransformOp(aff, hints);
   7: 
   8:         ...
   9: 
  10:         op.filter(srcBI, myBI);

View Full Code Here
   1:     Current = new BufferedImage(wide, high ,BufferedImage.TYPE_INT_ARGB);
   2:     AffineTransformOp scale = new AffineTransformOp(trans, Quality);
   3:         ...
   4:     scale.filter(Original, Current);
   5:     updateBoundingBox();
   6:         ...
   7:     SCurrent = new BufferedImage(wide, high, BufferedImage.TYPE_INT_ARGB);
   8:     scale.filter(Selected, SCurrent);
   9:   }

View Full Code Here

getBounds2D

public final Rectangle2D getBounds2D(BufferedImage src)
Returns the bounding box of the transformed destination. The rectangle returned is the actual bounding box of the transformed points. The coordinates of the upper-left corner of the returned rectangle might not be (0, 0).
Specified by:
getBounds2D in interface BufferedImageOp
Parameters:
src - The BufferedImage to be transformed.
Returns:
The Rectangle2D representing the destination's bounding box.

getBounds2D

public final Rectangle2D getBounds2D(Raster src)
Returns the bounding box of the transformed destination. The rectangle returned will be the actual bounding box of the transformed points. The coordinates of the upper-left corner of the returned rectangle might not be (0, 0).
Specified by:
getBounds2D in interface RasterOp
Parameters:
src - The Raster to be transformed.
Returns:
The Rectangle2D representing the destination's bounding box.

getInterpolationType

public final int getInterpolationType()
Returns the interpolation type used by this op.
Returns:
the interpolation type.

getPoint2D

public final Point2D getPoint2D(Point2D srcPt,
                                Point2D dstPt)
Returns the location of the corresponding destination point given a point in the source. If dstPt is specified, it is used to hold the return value.
Specified by:
getPoint2D in interface BufferedImageOp
getPoint2D in interface RasterOp
Parameters:
srcPt - The Point2D that represents the source point.
dstPt - The Point2D in which to store the result.
Returns:
The Point2D in the destination that corresponds to the specified point in the source.

getRenderingHints

public final RenderingHints getRenderingHints()
Returns the rendering hints used by this transform operation.
Specified by:
getRenderingHints in interface BufferedImageOp
getRenderingHints in interface RasterOp
Returns:
The RenderingHints object associated with this op.

getTransform

public final AffineTransform getTransform()
Returns the affine transform used by this transform operation.
Returns:
The AffineTransform associated with this op.