本文整理了Java中java.awt.Graphics2D.rotate()
方法的一些代码示例,展示了Graphics2D.rotate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graphics2D.rotate()
方法的具体详情如下:
包路径:java.awt.Graphics2D
类名称:Graphics2D
方法名:rotate
暂无
代码示例来源:origin: jphp-group/jphp
@Signature
public PImage rotate(double angle)
{
double sin = Math.abs(Math.sin(Math.toRadians(angle))),
cos = Math.abs(Math.cos(Math.toRadians(angle)));
int w = image.getWidth(null), h = image.getHeight(null);
int neww = (int) Math.floor(w*cos + h*sin),
newh = (int) Math.floor(h*cos + w*sin);
BufferedImage bimg = new BufferedImage(neww, newh, image.getType());
Graphics2D g = bimg.createGraphics();
g.translate((neww-w)/2, (newh-h)/2);
g.rotate(Math.toRadians(angle), w/2, h/2);
g.drawRenderedImage(image, null);
g.dispose();
this.image = bimg;
return this;
}
代码示例来源:origin: looly/hutool
/**
* 旋转图片为指定角度<br>
* 来自:http://blog.51cto.com/cping1982/130066
*
* @param degree 旋转角度
* @return 旋转后的图片
* @since 3.2.2
*/
public Img rotate(int degree) {
final BufferedImage image = getValidSrcImg();
int width = image.getWidth(null);
int height = image.getHeight(null);
final Rectangle rectangle = calcRotatedSize(width, height, degree);
final BufferedImage targetImg = new BufferedImage(rectangle.width, rectangle.height, getTypeInt());
Graphics2D graphics2d = targetImg.createGraphics();
// 抗锯齿
graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
// 从中心旋转
graphics2d.translate((rectangle.width - width) / 2, (rectangle.height - height) / 2);
graphics2d.rotate(Math.toRadians(degree), width / 2, height / 2);
graphics2d.drawImage(image, 0, 0, null);
graphics2d.dispose();
this.targetImage = targetImg;
return this;
}
代码示例来源:origin: looly/hutool
/**
* 旋转图片为指定角度<br>
* 来自:http://blog.51cto.com/cping1982/130066
*
* @param degree 旋转角度
* @return 旋转后的图片
* @since 3.2.2
*/
public Img rotate(int degree) {
final BufferedImage image = getValidSrcImg();
int width = image.getWidth(null);
int height = image.getHeight(null);
final Rectangle rectangle = calcRotatedSize(width, height, degree);
final BufferedImage targetImg = new BufferedImage(rectangle.width, rectangle.height, getTypeInt());
Graphics2D graphics2d = targetImg.createGraphics();
// 抗锯齿
graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
// 从中心旋转
graphics2d.translate((rectangle.width - width) / 2, (rectangle.height - height) / 2);
graphics2d.rotate(Math.toRadians(degree), width / 2, height / 2);
graphics2d.drawImage(image, 0, 0, null);
graphics2d.dispose();
this.targetImage = targetImg;
return this;
}
代码示例来源:origin: org.apache.poi/poi
graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());
graphics.scale(-1, 1);
graphics.translate(-anchor.getX(), -anchor.getY());
graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
graphics.scale(1, -1);
graphics.translate(-anchor.getX(), -anchor.getY());
graphics.translate(centerX, centerY);
graphics.rotate(Math.toRadians(rotation));
graphics.translate(-centerX, -centerY);
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
g.translate((neww-w)/2, (newh-h)/2);
g.rotate(Math.toRadians(amount), w/2, h/2);
g.drawRenderedImage(src, null);
g.dispose();
代码示例来源:origin: stackoverflow.com
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.translate(this.getWidth() / 2, this.getHeight() / 2);
g2d.rotate(theta);
g2d.translate(-image.getWidth(this) / 2, -image.getHeight(this) / 2);
g2d.drawImage(image, 0, 0, null);
代码示例来源:origin: org.apache.poi/poi-ooxml
graphics.translate(bounds.x, bounds.y);
graphics.scale(1, -1);
graphics.translate(0, -bounds.height
+ graphics.getFontMetrics().getMaxCharBounds(graphics)
.getHeight());
graphics.translate(-bounds.width, 0);
graphics.rotate(txtAngle);
代码示例来源:origin: org.apache.poi/poi
final double ax = anchor.getX();
final double ay = anchor.getY();
graphics.translate(ax + anchor.getWidth(), ay);
graphics.scale(-1, 1);
graphics.translate(-ax, -ay);
final double cx = anchor.getCenterX();
final double cy = anchor.getCenterY();
graphics.translate(cx, cy);
graphics.rotate(Math.toRadians(textRot));
graphics.translate(-cx, -cy);
final double cy = anchor.getCenterY();
graphics.translate(cx, cy);
graphics.rotate(Math.toRadians(deg));
graphics.translate(-cx, -cy);
代码示例来源:origin: i2p/i2p.i2p
void transform(int x, int y, double angle) {
gd.translate(x, y);
gd.rotate(angle);
}
代码示例来源:origin: magefree/mage
private Graphics2D getAftermathHalfContext(Graphics2D g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.translate(rightHalf.x, rightHalf.y);
g2.rotate(Math.PI / 2);
g2.translate(0, -rightHalf.w);
return g2;
}
代码示例来源:origin: magefree/mage
private Graphics2D getLeftHalfContext(Graphics2D g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.translate(leftHalf.x, leftHalf.y);
g2.rotate(-Math.PI / 2);
g2.translate(-leftHalf.cw, 0);
return g2;
}
代码示例来源:origin: magefree/mage
private Graphics2D getRightHalfContext(Graphics2D g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.translate(rightHalf.x, rightHalf.y);
g2.rotate(-Math.PI / 2);
g2.translate(-rightHalf.cw, 0);
return g2;
}
代码示例来源:origin: magefree/mage
private static BufferedImage rotateImage(BufferedImage image, double angle) {
double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
int width = image.getWidth(), height = image.getHeight();
int newWidth = (int) Math.floor(width * cos + height * sin), newHeight = (int) Math.floor(height * cos + width * sin);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();
BufferedImage result = gc.createCompatibleImage(newWidth, newHeight, Transparency.TRANSLUCENT);
Graphics2D g = result.createGraphics();
g.translate((newWidth - width) / 2, (newHeight - height) / 2);
g.rotate(angle, width / 2, height / 2);
g.drawRenderedImage(image, null);
g.dispose();
return result;
}
代码示例来源:origin: stackoverflow.com
/**
* Rotates an image. Actually rotates a new copy of the image.
*
* @param img The image to be rotated
* @param angle The angle in degrees
* @return The rotated image
*/
public static Image rotate(Image img, double angle)
{
double sin = Math.abs(Math.sin(Math.toRadians(angle))),
cos = Math.abs(Math.cos(Math.toRadians(angle)));
int w = img.getWidth(null), h = img.getHeight(null);
int neww = (int) Math.floor(w*cos + h*sin),
newh = (int) Math.floor(h*cos + w*sin);
BufferedImage bimg = toBufferedImage(getEmptyImage(neww, newh));
Graphics2D g = bimg.createGraphics();
g.translate((neww-w)/2, (newh-h)/2);
g.rotate(Math.toRadians(angle), w/2, h/2);
g.drawRenderedImage(toBufferedImage(img), null);
g.dispose();
return toImage(bimg);
}
代码示例来源:origin: stackoverflow.com
public static BufferedImage rotate(BufferedImage image, double angle) {
double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
int w = image.getWidth(), h = image.getHeight();
int neww = (int)Math.floor(w*cos+h*sin), newh = (int) Math.floor(h * cos + w * sin);
GraphicsConfiguration gc = getDefaultConfiguration();
BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT);
Graphics2D g = result.createGraphics();
g.translate((neww - w) / 2, (newh - h) / 2);
g.rotate(angle, w / 2, h / 2);
g.drawRenderedImage(image, null);
g.dispose();
return result;
}
private static GraphicsConfiguration getDefaultConfiguration() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
return gd.getDefaultConfiguration();
}
代码示例来源:origin: nguyenq/tess4j
/**
* Rotates an image.
*
* @param image the original image
* @param angle the degree of rotation
* @return a rotated image
*/
public static BufferedImage rotateImage(BufferedImage image, double angle) {
double theta = Math.toRadians(angle);
double sin = Math.abs(Math.sin(theta));
double cos = Math.abs(Math.cos(theta));
int w = image.getWidth();
int h = image.getHeight();
int newW = (int) Math.floor(w * cos + h * sin);
int newH = (int) Math.floor(h * cos + w * sin);
BufferedImage tmp = new BufferedImage(newW, newH, image.getType());
Graphics2D g2d = tmp.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2d.translate((newW - w) / 2, (newH - h) / 2);
g2d.rotate(theta, w / 2, h / 2);
g2d.drawImage(image, 0, 0, null);
g2d.dispose();
return tmp;
}
代码示例来源:origin: magefree/mage
protected void paintComponent(Graphics g) {
super.paintComponent(g);
float ex = endX - startX;
float ey = endY - startY;
if (ex == 0 && ey == 0) {
return;
}
float length = (float) Math.sqrt(ex * ex + ey * ey);
float bendPercent = (float) Math.asin(ey / length);
if (endX > startX) {
bendPercent = -bendPercent;
}
Area arrow = getArrow(length, bendPercent);
Graphics2D g2d = (Graphics2D) g;
g2d.translate(startX, startY);
g2d.rotate(Math.atan2(ey, ex));
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setComposite(composite);
g2d.setColor(this.color);
g2d.fill(arrow);
g2d.setColor(Color.BLACK);
g2d.draw(arrow);
}
代码示例来源:origin: apache/pdfbox
g.translate(x, y);
g.rotate(Math.toRadians(rotation));
g.drawImage(image, 0, 0, null);
g.dispose();
代码示例来源:origin: magefree/mage
@Override
public void paint(Graphics g) {
if (!displayEnabled) {
return;
}
if (!isValid()) {
super.validate();
}
Graphics2D g2d = (Graphics2D) g;
if (transformAngle < 1) {
float edgeOffset = (cardWidth + cardXOffset) / 2f;
g2d.translate(edgeOffset * (1 - transformAngle), 0);
g2d.scale(transformAngle, 1);
}
if (tappedAngle + flippedAngle > 0) {
g2d = (Graphics2D) g2d.create();
float edgeOffset = cardWidth / 2f;
double angle = tappedAngle + (Math.abs(flippedAngle - FLIPPED_ANGLE) < 0.001 ? 0 : flippedAngle);
g2d.rotate(angle, cardXOffset + edgeOffset, cardYOffset + cardHeight - edgeOffset);
}
super.paint(g2d);
}
代码示例来源:origin: stackoverflow.com
Graphics2D g2 = (Graphics2D)g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.translate(100, 150);
g2.rotate(0.4);
g2.setPaint(Color.red);
g2.fill(s);
内容来源于网络,如有侵权,请联系作者删除!