本文整理汇总了Java中java.awt.geom.AffineTransform.rotate方法的典型用法代码示例。如果您正苦于以下问题:Java AffineTransform.rotate方法的具体用法?Java AffineTransform.rotate怎么用?Java AffineTransform.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.AffineTransform
的用法示例。
在下文中一共展示了AffineTransform.rotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: draw
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
@Override
public void draw(Graphics2D graphics) {
graphics.setStroke(JSpaceSettlersComponent.THIN_STROKE);
final AffineTransform transform =
AffineTransform.getTranslateInstance(drawLocation.getX(), drawLocation.getY());
transform.rotate(-Math.PI / 2.0);
transform.scale(scale, scale);
Shape newFlagShape = transform.createTransformedShape(FLAG_SHAPE);
// color the flag to match the team
graphics.setPaint(flagColor);
graphics.fill(newFlagShape);
}
示例2: girar
import java.awt.geom.AffineTransform; //导入方法依赖的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));
}
示例3: init
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
int w = dim.width;
int h = dim.height;
double theta = Math.toRadians(15);
double cos = Math.cos(theta);
double sin = Math.sin(theta);
double xsize = sin * h + cos * w;
double ysize = sin * w + cos * h;
double scale = Math.min(w / xsize, h / ysize);
xsize *= scale;
ysize *= scale;
AffineTransform at = new AffineTransform();
at.translate((w - xsize) / 2.0, (h - ysize) / 2.0);
at.translate(sin * h * scale, 0.0);
at.rotate(theta);
g2d.transform(at);
dim.setSize(scaleForTransform(at, dim));
}
示例4: createArrow
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
protected Shape createArrow(float fx, float fy, float tx, float ty) {
float dx = tx - fx;
float dy = ty - fy;
float D = (float) Math.sqrt(dx * dx + dy * dy);
float z = (dx <= 0) ? fx - D : fx + D;
double alpha = (dx > 0) ? Math.asin(dy / D) : -Math.asin(dy / D);
float h = arrowHeight;
int n = (int) (D / h);
h = D / (float) (n + 1);
float dec = (dx <= 0) ? h : -h;
GeneralPath gp = new GeneralPath();
for (int i = 0; i <= n; i++) {
gp.moveTo(z + dec, fy - arrowWidth);
gp.lineTo(z, fy);
gp.lineTo(z + dec, fy + arrowWidth);
z += dec;
}
gp.closePath();
AffineTransform affineTransform = new AffineTransform();
affineTransform.rotate(alpha, fx, fy);
return gp.createTransformedShape(affineTransform);
}
示例5: drawYLabel
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private void drawYLabel(Graphics2D chartGraphics) {
if (yAxisLabel != null) {
// Strings are drawn from the baseline position of the leftmost char.
int yPosYAxisLabel = heatMapC.y + (yAxisLabelSize.width / 2);
int xPosYAxisLabel = (margin / 2) + yAxisLabelAscent;
chartGraphics.setFont(axisLabelsFont);
chartGraphics.setColor(axisLabelColour);
// Create 270 degree rotated transform.
AffineTransform transform = chartGraphics.getTransform();
AffineTransform originalTransform = (AffineTransform) transform.clone();
transform.rotate(Math.toRadians(270), xPosYAxisLabel, yPosYAxisLabel);
chartGraphics.setTransform(transform);
// Draw string.
chartGraphics.drawString(yAxisLabel, xPosYAxisLabel, yPosYAxisLabel);
// Revert to original transform before rotation.
chartGraphics.setTransform(originalTransform);
}
}
示例6: transformEdgeShape
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private void transformEdgeShape( Point2D down, Point2D out ) {
float x1 = (float) down.getX();
float y1 = (float) down.getY();
float x2 = (float) out.getX();
float y2 = (float) out.getY();
AffineTransform xform = AffineTransform.getTranslateInstance( x1, y1 );
float dx = x2 - x1;
float dy = y2 - y1;
float thetaRadians = (float) Math.atan2( dy, dx );
xform.rotate( thetaRadians );
float dist = (float) Math.sqrt( dx * dx + dy * dy );
xform.scale( dist / rawEdge.getBounds().getWidth(), 1.0 );
edgeShape = xform.createTransformedShape( rawEdge );
}
示例7: paintComponent
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Rotate image to horizontal
AffineTransform at = new AffineTransform();
at.translate(getWidth() / 2, getHeight() / 2);
at.rotate(this.getRotationAngle(associatedBoat.getOrientation()));
at.translate(-image.getWidth()/2, -image.getHeight()/2);
try {
Graphics2D g2d = (Graphics2D) g;
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.getOpacity()));
g2d.drawImage(this.image,at,null);
} catch (ClassCastException e) {
e.printStackTrace();
}
}
示例8: rotate
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static BufferedImage rotate(final BufferedImage bufferedImage, final double radians) {
final AffineTransform tx = new AffineTransform();
tx.rotate(radians, bufferedImage.getWidth() / 2.0, bufferedImage.getHeight() / 2.0);
final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
return op.filter(bufferedImage, null);
}
示例9: getClipRect2D
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
* Gets the region currently displayed in Projection coordinates.
* @return the region currently displayed in Projection coordinates.
*/
public Rectangle2D getClipRect2D() {
Rectangle r = getVisibleRect();
Dimension dim = getPreferredSize();
r.width = Math.min(r.width, dim.width);
r.height = Math.min(r.height, dim.height);
AffineTransform at = new AffineTransform();
if(rotation==1) {
at.translate( 0., dim.getHeight() );
at.rotate(-.5*Math.PI);
} else if( rotation==2 ) {
at.translate( dim.getWidth(), dim.getHeight() );
at.rotate( Math.PI );
} else if( rotation == 3) {
at.translate( dim.getWidth(), 0. );
at.rotate( .5*Math.PI );
}
if(rotation != 0) {
Point2D p1 = at.transform(new Point(r.x,r.y), null);
Point2D p2 = at.transform(new Point(r.x+r.width,r.y+r.width), null);
r.x = (int) Math.min(p1.getX(), p2.getX());
r.width = (int) Math.max(p1.getX(), p2.getX()) - r.x;
r.y = (int) Math.min(p1.getY(), p2.getY());
r.height = (int) Math.max(p1.getY(), p2.getY()) - r.y;
}
if(mapBorder != null) {
Insets ins = mapBorder.getBorderInsets(this);
r.width -= ins.left + ins.right;
r.height -= ins.top + ins.bottom;
}
Rectangle2D.Double r2d = new Rectangle2D.Double(
r.getX()/zoom, r.getY()/zoom,
r.getWidth()/zoom, r.getHeight()/zoom);
return r2d;
}
示例10: makeAT
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static AffineTransform makeAT(Mode mode, Point2D txpt,
double radians)
{
AffineTransform at;
double tx = (txpt == null) ? 0.0 : txpt.getX();
double ty = (txpt == null) ? 0.0 : txpt.getY();
switch (mode) {
case GET:
if (txpt != null) {
at = AffineTransform.getRotateInstance(radians, tx, ty);
} else {
at = AffineTransform.getRotateInstance(radians);
}
break;
case SET:
at = makeRandomAT();
if (txpt != null) {
at.setToRotation(radians, tx, ty);
} else {
at.setToRotation(radians);
}
break;
case MOD:
at = makeRandomAT();
at.setToIdentity();
if (txpt != null) {
at.rotate(radians, tx, ty);
} else {
at.rotate(radians);
}
break;
default:
throw new InternalError("unrecognized mode: "+mode);
}
return at;
}
示例11: rotate
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public void rotate( Point2D center, double angle ) {
BufferedImage im = new BufferedImage( width, height, image.TYPE_INT_RGB);
Graphics2D g = im.createGraphics();
AffineTransform at = new AffineTransform();
at.rotate( -angle, center.getX(), center.getY() );
g.drawRenderedImage( image, at);
image = im;
repaint();
}
示例12: finishButtonActionPerformed
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private void finishButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finishButtonActionPerformed
Component comp = (Component)SwingUtilities.getRoot(mapComponent);
comp.setVisible(false);
if (this.destinationGeoSet != null) {
GeoImage geoImage = (GeoImage)this.imageGeoSet.getGeoObject(0);
GeoPath testPath = new GeoPath();
testPath.rectangle(geoImage.getBounds2D());
geoImage.setSelectable(true);
java.awt.image.BufferedImage image = geoImage.getBufferedImage();
AffineTransform affineTransform = new AffineTransform();
//this.transformation.getRotation()
//affineTransform.scale (2, 2);
//affineTransform.translate(500, -200);
affineTransform.rotate(Math.PI / 4, image.getWidth()/2, image.getHeight()/2);
//affineTransform.translate(0, -image.getHeight());
//affineTransform.scale(1, -1);
geoImage.transform(affineTransform);
//geoImage.transform(transformation.getAffineTransform());
this.destinationGeoSet.addGeoObject(geoImage);
this.destinationGeoSet.addGeoObject(testPath);
}
}
示例13: createArrow
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
protected Shape createArrow(float fx, float fy, float tx, float ty) {
float dx = tx - fx;
float dy = ty - fy;
float D = (float) Math.sqrt(dx * dx + dy * dy);
float z = (dx <= 0) ? fx - D : fx + D;
double alpha = (dx > 0) ? Math.asin(dy / D) : -Math.asin(dy / D);
float h = arrowWidth * 2;
int n = (int) (D / h);
h = D / (float) (n + 1);
if (n < 0)
n = 0;
float dec = (dx <= 0) ? h : -h;
GeneralPath gp = new GeneralPath();
for (int i = 0; i <= n; i++) {
gp.moveTo(z + dec, fy - arrowWidth);
gp.lineTo(z + dec / 2f, fy - arrowWidth);
gp.lineTo(z, fy);
gp.lineTo(z + dec / 2f, fy + arrowWidth);
gp.lineTo(z + dec, fy + arrowWidth);
gp.lineTo(z + dec / 2f, fy);
z += dec;
}
gp.closePath();
AffineTransform affineTransform = new AffineTransform();
affineTransform.rotate(alpha, fx, fy);
return gp.createTransformedShape(affineTransform);
}
示例14: rotate
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public ImageUtils rotate(int angle){
if (angle == 0) {
return this;
}
if (angle>360) {
angle = Math.abs(angle)%360;
}
if (angle<0){
if (Math.abs(angle)<360) {
angle = 360+angle;
}else {
angle =(Math.abs(angle)/360+1)*360+angle;
}
}
int width = this.dealedImage.getWidth();
int height = this.dealedImage.getHeight();
int new_w, new_h;
int new_radian = angle;
if (angle <= 90) {
new_w = (int) (width * Math.cos(Math.toRadians(new_radian)) + height * Math.sin(Math.toRadians(new_radian)));
new_h = (int) (height * Math.cos(Math.toRadians(new_radian)) + width * Math.sin(Math.toRadians(new_radian)));
} else if (angle <= 180) {
new_radian = angle - 90;
new_w = (int) (height * Math.cos(Math.toRadians(new_radian)) + width * Math.sin(Math.toRadians(new_radian)));
new_h = (int) (width * Math.cos(Math.toRadians(new_radian)) + height * Math.sin(Math.toRadians(new_radian)));
} else if (angle <= 270) {
new_radian = angle - 180;
new_w = (int) (width * Math.cos(Math.toRadians(new_radian)) + height * Math.sin(Math.toRadians(new_radian)));
new_h = (int) (height * Math.cos(Math.toRadians(new_radian)) + width * Math.sin(Math.toRadians(new_radian)));
} else {
new_radian = angle - 270;
new_w = (int) (height * Math.cos(Math.toRadians(new_radian)) + width * Math.sin(Math.toRadians(new_radian)));
new_h = (int) (width * Math.cos(Math.toRadians(new_radian)) + height * Math.sin(Math.toRadians(new_radian)));
}
BufferedImage toStore = new BufferedImage(new_w, new_h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = toStore.createGraphics();
AffineTransform affineTransform = new AffineTransform();
affineTransform.rotate(Math.toRadians(angle), width / 2, height / 2);
if (angle != 180) {
AffineTransform translationTransform = this.findTranslation(affineTransform, this.dealedImage, angle);
affineTransform.preConcatenate(translationTransform);
}
g.setColor(Color.WHITE);
g.fillRect(0, 0, new_w, new_h);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawRenderedImage(this.dealedImage, affineTransform);
g.dispose();
this.dealedImage = toStore;
return this;
}
示例15: readImage
import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static BufferedImage readImage(Path file, int orientation) throws IOException {
try {
BufferedImage image = ImageIO.read(file.toFile());
int width = image.getWidth();
int height = image.getHeight();
AffineTransform t = new AffineTransform();
switch (orientation) {
case 2: // Flip X
t.scale(-1.0, 1.0);
t.translate(-width, 0);
break;
case 3: // PI rotation
t.translate(width, height);
t.rotate(Math.PI);
break;
case 4: // Flip Y
t.scale(1.0, -1.0);
t.translate(0, -height);
break;
case 5: // - PI/2 and Flip X
t.rotate(-Math.PI / 2);
t.scale(-1.0, 1.0);
break;
case 6: // -PI/2 and -width
t.translate(height, 0);
t.rotate(Math.PI / 2);
break;
case 7: // PI/2 and Flip
t.scale(-1.0, 1.0);
t.translate(-height, 0);
t.translate(0, width);
t.rotate(3 * Math.PI / 2);
break;
case 8: // PI / 2
t.translate(0, width);
t.rotate(3 * Math.PI / 2);
break;
default:
return image;
}
AffineTransformOp op = new AffineTransformOp(t, AffineTransformOp.TYPE_BICUBIC);
BufferedImage destinationImage = op.createCompatibleDestImage(image, (image.getType() == BufferedImage.TYPE_BYTE_GRAY) ? image.getColorModel() : null);
Graphics2D g = destinationImage.createGraphics();
g.setBackground(Color.WHITE);
g.clearRect(0, 0, destinationImage.getWidth(), destinationImage.getHeight());
destinationImage = op.filter(image, destinationImage);
return destinationImage;
} catch (IOException ex) {
throw new IOException(file.toString() + ": " + ex.getMessage(), ex);
}
}