AffineTransform.rotate() – how do I xlate, rotate, and scale at the same time?

Okay, this is a little slight of hand. The example code will only work for 90 degree increments (it was only designed this way), to do smaller increments you to use some trig to calculate the image width and height (there’s a answer somewhere for that to ;)) public class ImagePane extends JPanel { private … Read more

Java 2d rotation in direction mouse point

Using the Graphics2D rotation method is indeed the easiest way. Here’s a simple implementation: int centerX = width / 2; int centerY = height / 2; double angle = Math.atan2(centerY – mouseY, centerX – mouseX) – Math.PI / 2; ((Graphics2D)g).rotate(angle, centerX, centerY); g.fillRect(…); // draw your rectangle If you want to remove the rotation when … Read more

Rotate a buffered image in Java

As always, the Internet to the rescue. So, this is some code which I hobbled together from other resources/post/blogs which will return a new image which is sized so it will contain the rotated image public BufferedImage rotateImageByDegrees(BufferedImage img, double angle) { double rads = Math.toRadians(angle); double sin = Math.abs(Math.sin(rads)), cos = Math.abs(Math.cos(rads)); int w … Read more

Rotating Image with AffineTransform

The major problem (that I can see) is the translation of the Graphics context which is offset the position that the rotation will take place. I “think” rotation by default occurs at the top/left corner of the Graphics context (where it’s 0x0 position is, which you’ve translated to something else), this could be causing the … Read more

Android: How to rotate a bitmap on a center point

I hope the following sequence of code will help you: Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, config); Canvas canvas = new Canvas(targetBitmap); Matrix matrix = new Matrix(); matrix.setRotate(mRotation,source.getWidth()/2,source.getHeight()/2); canvas.drawBitmap(source, matrix, new Paint()); If you check the following method from ~frameworks\base\graphics\java\android\graphics\Bitmap.java public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean … Read more

How to rotate the background image in the container?

Very well done and answered here – http://www.sitepoint.com/css3-transform-background-image/ #myelement:before { content: “”; position: absolute; width: 200%; height: 200%; top: -50%; left: -50%; z-index: -1; background: url(background.png) 0 0 repeat; -webkit-transform: rotate(30deg); -moz-transform: rotate(30deg); -ms-transform: rotate(30deg); -o-transform: rotate(30deg); transform: rotate(30deg); }