Is it possible to rotate and scale an image?

Is it possible to rotate and scale an image with Grapchis2D at the same time?
One method call to do it all?
lets say the original image size is 200x200
I can scale the image with
Graphics.drawImage(image, 0,0, 500,500,this);
But now i need to rotate it as well and keep the new size which is 500x500
how do i do that ?

Have you already tried the scale(double sx, double
sy) and rotate(double theta) methods of Graphics2D?no.

Similar Messages

  • Rotate and scale an image witohout deforming it

    Hello you all!
    I have to rotate and scale an image, but i don't wont to deform it.
    I'm thinking to something like 16/9 images on 4/3 screens (with two horizontal or vertical black lines around the scaled image)...
    I thinked to transform the image in bitmap format, then create a bigger image and fill the empty spaces with zero-pixels...
    Is there a simplest and more efficient way to do it with 2D java classes?
    Thank you!

    See reply 8 in Help to rotate image for an idea.

  • Photoshop poor transformation quality (rotation and scale at once)

    When smart object, or layer are transformed (rotation and scale) at once, that cause bad result. Unnecessary work around is rotate object first, then convert to another smart object and then scale it.

    As far as I know with a SO the work-around should not make a difference (and in a quick test on my station it did not).
    Edit: Sorry, I had read inattentively and missed that you converted the SO to a SO again – that does make a difference naturally.
    You could change your Perferences > General > Image Interpolation setting.

  • Is there any way to rotate and scale type live?

    I'm using cs6 and I want to rotate and scale individual letters.  Whenever I try to do it I am only altering the text box.  Is there any way I can do the same thing with the text itself without rasterizing it?

    Carlos has a script that divides text frames into individual characters. You can use the transform tool to edit the individual text objects.
    the script can be found here, the .jsx version reply #6 is what you would use
    http://forums.adobe.com/message/4001567

  • Rotating and Translating an Image

    I am making a game with a tank that can rotate and move forwards and backwards.
    I am able to get the tank Image to rotate, but when I call a translation, it resets the image back to its original image. How can I fix this?

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TankGame extends JPanel {
        Walker walker = new Walker(this);
        BufferedImage image;
        AffineTransform at = new AffineTransform();
        Point2D.Double loc = new Point2D.Double(200,150);
        double theta = 0;
        double t = 3.0;
        boolean goAhead = true;
        public TankGame(BufferedImage image) {
            this.image = image;
            setTransform();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.drawRenderedImage(image, at);
            //g2.setPaint(Color.red);
            //g2.fill(new Ellipse2D.Double(loc.x-2, loc.y-2, 4, 4));
        public synchronized void step() {
            int sign = goAhead ? 1 : -1;
            double x = loc.x + sign*t*Math.cos(theta);
            double y = loc.y + sign*t*Math.sin(theta);
            loc.setLocation(x, y);
            setTransform();
            repaint();
        private void setTransform() {
            double x = loc.x - image.getWidth()/2;
            double y = loc.y - image.getHeight()/2;
            at.setToTranslation(x, y);
            at.rotate(theta, image.getWidth()/2, image.getHeight()/2);
        private JPanel getUIPanel() {
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(1,0,1,0);
            gbc.weightx = 1.0;
            String[] ids = { "ahead", "stop", "back" };
            ActionListener al = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    String ac = e.getActionCommand();
                    if(ac.equals("stop")) {
                        walker.stop();
                    } else {
                        if(ac.equals("ahead")) {
                            goAhead = true;
                        } else if(ac.equals("back")) {
                            goAhead = false;
                        walker.start();
            for(int j = 0; j < ids.length; j++) {
                JButton button = new JButton(ids[j]);
                button.addActionListener(al);
                if(j == ids.length-1)
                    gbc.gridwidth = GridBagConstraints.REMAINDER;
                panel.add(button, gbc);
            JSlider slider = new JSlider(-180, 180, 0);
            slider.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    int angle = ((JSlider)e.getSource()).getValue();
                    theta = Math.toRadians(angle);
                    setTransform();
                    repaint();
            gbc.gridwidth = 3;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            panel.add(slider, gbc);
            return panel;
        public static void main(String[] args) throws IOException {
            String path = "images/geek/geek----t.gif";
            BufferedImage image = ImageIO.read(new File(path));
            TankGame test = new TankGame(image);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(test);
            f.add(test.getUIPanel(), "Last");
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
    class Walker implements Runnable {
        TankGame game;
        Thread thread;
        boolean moving = false;
        long delay = 100;
        public Walker(TankGame tg) {
            game = tg;
        public void run() {
            while(moving) {
                try {
                    Thread.sleep(delay);
                } catch(InterruptedException e) {
                    moving = false;
                game.step();
        public void start() {
            if(!moving) {
                moving = true;
                thread = new Thread(this);
                thread.setPriority(Thread.NORM_PRIORITY);
                thread.start();
        public void stop() {
            moving = false;
            if(thread != null)
                thread.interrupt();
            thread = null;
    }

  • Duplicating a SymbolItem's Rotation and Scale "Properties" (Previous Transformations)

    So, I have a script that runs through a document and replaces SymbolItem Objects with "new SymbolItem Objects of updated symbols."
    My problem is that I need to replicate any transformations that were made on the original SymbolItem Objects (rotation, scale, ect.) and put these transformations on the replacement.
    The new symbols are not the same height and width as the original symbols (many symbols contain only text which has been updated).  So, scaling will need to be transferred as a ratio between the SymbolItem's original size (the size of the Symbol) and it's current size.
    Sorry if this is a common question.  I can't seem to find the answere anywhere.
    Thanks!
    ~ Clint G.

    I answered this one myself.  Rather than make a new SymbolItem of the "updated symbol", I simply needed to set the "symbol" property of my original SymbolItem Object to the my new "UpdatedSymbol".  The transformation properties stay intact. 

  • Rotating and cropping an image.

    I am taking a Photoshop for school and we are using CS5. I have CS6 and I'm stuck on my picture rotating back straight when I am trying to crop it.  I use the rotate view and rotate it 6degrees. As soon as I hit the crop button the picture goes straight. How can I keep my picture rotated to the 6degrees and crop it without the perspective crop tool?

    Rotate view only rotates...  the view; not the actual picture.  It's temporary and non-destructive. It's used to help move the canvas to a better angle for drawing brush strokes.
    You want to actually rotate the image or canvas.  Either Ctrl T for Free Transform and rotate by moving the cursor outside one of the corners and dragging.  Or Edit > Transform > Rotate

  • Rotate and save an image

    Hi All,
    I am a new comer. Could I ask you a question about java 2D? I want to rotate an image and then save it as another file, but now I don't know how to make the rotated iamge as a new one so that I can save it. Could you give me some ideas?
    Thanks,
    Regards,

    look up the Affine Transforms or use JAI.

  • Rotating and dragging of image using mouse

    hi everyone,
    I've got problems with dragging and rotating of images using the mouse
    Can anyone show me how to that?
    Thanks a million

    Implement a MouseMotionListener on the Panel that you want to drag the image on.
    public void mouseDragged  (   MouseEvent e   )
           if ( e.getModifiers() == MouseEvent.BUTTON1_MASK )
              if ( dragged )
                  processMove( new Point2D.Double( e.getPoint().x, e.getPoint().y ) );
             else
               wasDragged = true;
                  dragged    = true;
                  dragPoint  = new Point2D.Double( e.getPoint().x, e.getPoint().y );
                  xDiff      = 0;
                  yDiff      = 0;
    private void processMove
         Point2D.Double    point
              Point2D.Double paintPoint = new Point2D.Double( point.x - dragPoint.x, point.y - dragPoint.y );
           BufferedImage  imageBak   = getCurrentBackgroundImage();
           BufferedImage  background = new BufferedImage( imageBak.getWidth(), imageBak.getHeight(), imageBak.getType() );
           Graphics2D     gr         = background.createGraphics();
           gr.setColor( adaptee.getUserProfile().getBackgroundColor() );
           gr.fillRect( 0, 0, imageBak.getWidth(), imageBak.getHeight() );
           gr.drawImage( imageBak, null, (int) paintPoint.x, (int) paintPoint.y );
              gr.finalize();
           xDiff += paintPoint.x;
           yDiff += paintPoint.y;
           dragPoint = point;
           getGraphicsForPanelToDrawOn()..drawImage( background, null, 0, 0 );       
           setCurrentBackgroundImage(  background );
              }

  • Rotating and saving an image

    Hi, i'm trying to rotate an image and then save the rotated image to the hard drive in jpeg format. I've managed to get the rotation part working, but i can't seem to save the image correctly.

    Here is some code. You'll need to catch exceptions etc.
    BufferedImage expImage = new BufferedImage( (int)component.getWidth(), (int)component.getHeight(), BufferedImage.TYPE_INT_RGB );
                   Graphics g2d = expImage.getGraphics();
                   draftGrid.update(g2d);
                   layoutGrid.update(g2d);
                   g2d.dispose();
                        fileName = verifyFileName(fileName, "jpeg");
                        OutputStream out = new FileOutputStream( fileName );
                        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
                        encoder.encode(expImage);
                        out.flush();
                        out.close();
                        expImage.flush();
    /** This draft has been saved to fileName **/

  • How Can I Rotate and Zoom?

    Let's say I have a circle that's a large, detailed image. I want to be able to rotate and zoom to different points on that circle. How can that be accomplished in Muse? Thanks!

    What you want to do isn't possible with just Muse if I understand what you are trying to do correctly. I am assuming you want the user to be able to rotate and zoom the image?
    If so, then Edge Animate would be the tool you need and then import that into your Muse project.

  • Rotating and scaling graphics

    hi i need to rotate and scale a graphic on a canvas. i know that Affine Transform can do this (i think) but i dont know how to use it. i can get it to slide with the following method: Would it be sort of the same, or completely different?
    thanks
    Pedge
    public void Xslide(float dist)
    for (int i=0; i<vertex.size(); i++)
    ((Point2D)vertex.elementAt(i)).Xslide(dist);
    public void Xslide(float dist)
    x = x + dist;
    }

    if you have Shape object, you can use AffineTransform as follows:AffineTransform trans = new AffineTransform();
    trans.setToRotation(float) or trans.setToScale(double, double);
    Shape transformedShape = trans.createTransformedShape(originalShape);if you want to transform everything in a Graphics object, you can use the same AffineTransform using Graphics2D.transform(trans);
    I hope this helps!
    -JBoeing

  • Cannot move and scale wallpaper on my mini iOS 7.1.2

    Yesterday I updated my 16GB iPad mini to iOS 7.1.2. Today I wanted to change the wallpaper but can't get the mini to "move and scale" the photo I chose. I have tried the suggested remedies posted for the last iOS update (this past fall): turn off "Reduce Motion," try again (no dice).  Edit the photo choosing the 5x7 aspect ration, save, try again (no dice). Go to photos and send the photo to wallpaper, try again (still no dice).
    Using two fingers I can move and scale the image but when I remove my fingers from the screen the image reverts to its original size and position.

    What happens when you try?
    Have you tried restarting or resetting your iPad?
    Restart: Press On/Off button until the Slide to Power Off slider appears, select Slide to Power Off and, after It shuts down, press the On/Off button until the Apple logo appears.
    Reset: Press the Home and On/Off buttons at the same time and hold them until the Apple logo appears (about 10-15 seconds).
    No data will be lost.

  • Performance issues with Motion (position, scale, rotate) and GTX 590

    I'm experiencing performance issues with my Premiere Pro CC when I scale, position or rotate a clip in the program monitor.
    I have no performance issues with playback! It's only, when i move something with the mouse or by changing the x,y-values of Position in the Motion-Dialog in video effects.
    Premiere then lags terribly and updates the program monitor only about once per second - this makes it very difficult and cumbersome to work and position things.
    On a second Premiere installation on my laptop, performance is fine and fluid - allthough it doesn't have GPU support and is a much slower computer.
    I'm pretty sure this has somehow to do with my graphic card, which is a Nvidia GTX 590.
    I was told by the support, that it is actually a dual graphic card, which is not supported/liked by Premiere.
    The thing is, until the latest Premiere update, I did not have performance issues at all with this card.
    I also read on the forum that others with the GTX 590 did not experience any problems with it
    So where does this come from?
    There is no change in performance whether or not I activate Mercury Playback Engine GPU acceleration.
    I also tried deactivating one of the 2 gpus, but there also was no change.
    Does anyone else know this problem and has anyone a solution?
    I'm running Premiere CC on a Win 7 64bit engine, Nvidia GTX 590, latest driver (of today),

    I am suffering from the same phenomenon since I updated just before christmas, I think.
    I am hardly able to do scaling, rotating and translating in the program monitor itslef - whil motion has been highlighted in teh effect controls.
    In the effect controls I can scale, rotate etc however.
    Also I have noticed there is a yellow box with handles in teh program monitor. I remember it was white before.
    I cannot figure out what to change in my preferences. What has happened?
    best,
    Hans Wessels
    Premiere CC
    Mac Pro OSX 10.7.5
    16 GB 1066 MHz DD3
    2 X NVIDIA GeForce GT 120 512 MB

  • Problem with very slow scale, rotate and translate

    Hi -
    Here is the basic problem. I want to take a bufferedImage (read from a jpeg earlier on) and then rotate it according to an angle value (radians) and then resize it to fit within a specifically sized box. My code works fine, but... I have to do this in a loop up to 200 times. The process is often taking several minutes to complete. If this is simply a consequence of what I am trying to do, then I'll accept that, but surely I am just doing something wrong? Please help!
    Thanks - here is the (working but very slow) code
        public Graphics2D get_shape_image(Graphics2D g, BufferedImage b, double shaperotation, double space_width, double space_height,
                float x_scale_factor, float y_scale_factor, float shapeTransparency){
            // Work out the boundimg box size of the rotated image
            double imageWidth = (double) b.getWidth();
            double imageHeight = (double) b.getHeight();
            double cos = Math.abs( Math.cos(shaperotation));
            double sin = Math.abs( Math.sin(shaperotation));
            int new_width = (int) Math.floor(imageWidth * cos  +  imageHeight * sin);
            int new_height = (int) Math.floor(imageHeight * cos  +  imageWidth * sin);
            // Create the new bufferedImage of the right size
            BufferedImage transformed = new BufferedImage((int) new_width, (int) new_height, BufferedImage.TYPE_INT_RGB);
            // Create the transform and associated AffineTransformOperation
            AffineTransform at = new AffineTransform();
            AffineTransformOp affine_op;
            // Make sure our image to be rotated is in the middle of the new image
            double x_movement = ((double) (new_width / 2.0d)) - ((double) imageWidth / 2.0d);
            double y_movement = ((double) (new_height / 2.0d)) - ((double) imageHeight / 2.0d);
            at.setToTranslation(x_movement, y_movement);
            affine_op = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
            transformed = affine_op.filter(b, null);
            // Now we need to rotate the image according to the input rotation angle
            BufferedImage rotated = new BufferedImage((int) new_width, (int) new_height, BufferedImage.TYPE_INT_RGB);
            at.setToRotation(shaperotation, (double) new_width / 2.0d, new_height / 2.0d);
            affine_op = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
            rotated = affine_op.filter(transformed, null);
            // Do the scaling so that we fit into the grid sizes
            BufferedImage sizedImage = new BufferedImage((int) (space_width * x_scale_factor), (int) (space_height * y_scale_factor), BufferedImage.TYPE_INT_RGB);
            double xScale = (double) (space_width * x_scale_factor) / (double) new_width;
            double yScale = (double) (space_height * y_scale_factor) / (double) new_height;
            at.setToScale(xScale, yScale);
            affine_op = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
            sizedImage = affine_op.filter(rotated, null);
            // Finally translate the image to the correct position after scaling
            double x_adjust = (space_width / 2.0d) - ((space_width * x_scale_factor) / 2.0d);
            double y_adjust = (space_height / 2.0d) - ((space_height * y_scale_factor) / 2.0d);
            // Set the transparency
            AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, shapeTransparency);
            g.setComposite(ac);
            // Draw the image as long as it's above 0 size
            if (sizedImage.getWidth() > 0 && sizedImage.getHeight() > 0)
                g.drawImage(sizedImage, null, (int) x_adjust, (int) y_adjust);
            return g;
        }

    Your code worked okay in my system: busy at 200fps using 1.0f for alpha and
    the x/y scale_factor values.
    Here's another approach that isn't quite as busy.
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class XTest extends JPanel
        BufferedImage image;
        int gridWidth  = 100;
        int gridHeight = 100;
        double theta   = 0;
        double thetaInc;
        public XTest(BufferedImage image)
            this.image = image;
            thetaInc = Math.toRadians(1);
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            int w = getWidth();
            int h = getHeight();
            int imageW = image.getWidth();
            int imageH = image.getHeight();
            // rather than making a new BufferedImage for each step of
            // the rotation and scaling let's try to rotate, scale and
            // fit the source image directly into the grid by using
            // transforms...
            // rotation
            AffineTransform rotateXform = new AffineTransform();
            double x = (w - imageW)/2;
            double y = (h - imageH)/2;
            rotateXform.setToTranslation(x,y);
            rotateXform.rotate(theta, imageW/2.0, imageH/2.0);
            // get rotated size for source
            double cos = Math.abs( Math.cos(theta));
            double sin = Math.abs( Math.sin(theta));
            double rw = Math.rint(imageW * cos  +  imageH * sin);
            double rh = Math.rint(imageH * cos  +  imageW * sin);
            // scale factors to fit image into grid
            double xScale = gridWidth /  rw;
            double yScale = gridHeight / rh;
            // scale from center
            x = (1.0 - xScale)*w/2;
            y = (1.0 - yScale)*h/2;
            AffineTransform scaleXform = AffineTransform.getTranslateInstance(x,y);
            scaleXform.scale(xScale, yScale);
            scaleXform.concatenate(rotateXform);
            g2.drawRenderedImage(image, scaleXform);
            // markers
            // grid
            g2.setPaint(Color.red);
            int gx = (w - gridWidth)/2;
            int gy = (h - gridHeight)/2;
            g2.drawRect(gx, gy, gridWidth, gridHeight);
            // bounds of unscaled, rotated source image
            g2.setPaint(Color.blue);
            double rx = (w - rw)/2;
            double ry = (h - rh)/2;
            g2.draw(new Rectangle2D.Double(rx, ry, rw, rh));
        public void rotate()
            theta += thetaInc;
            repaint();
        public static void main(String[] args) throws IOException
            BufferedImage bi = ImageIO.read(new File("images/bclynx.jpg"));
            XTest test = new XTest(bi);
            Activator activator = new Activator(test);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(test);
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
            activator.start();
    class Activator implements Runnable
        XTest xTest;
        Thread thread;
        boolean animate;
        public Activator(XTest xt)
            xTest = xt;
            animate = false;
        public void run()
            while(animate)
                try
                    Thread.sleep(50);
                catch(InterruptedException ie)
                    animate = false;
                    System.out.println("interrupt");
                xTest.rotate();
        public void start()
            if(!animate)
                animate = true;
                thread = new Thread(this);
                thread.setPriority(Thread.NORM_PRIORITY);
                thread.start();
        public void stop()
            animate = false;
            thread = null;
    }

Maybe you are looking for

  • Cannot recognize any internal hard drives, hard drives good

    Hi, My macbook pro 13" (bought in august 09) recently stopped being able to recognize its internal drive. I've run it through all sorts of diagnostic software, but none has been able to recognize it at all. I've tried swapping out the hard drive to o

  • Grand Total % Variance

    Hi, I have a Report for GL Reconciliation and it shows Source System Balances and GL Balances along with the Variance in these two and % Variance. Sample data is as follows: Year     Month     SYS     Source System Bal GL Balances     Variance     %

  • Planning Reverse Fails: "Data Type" dimension

    One of my colleagues received the following error message in ODI when attempting to reverse a Planning application: org.apache.bsf.BSFException: exception from Jython: Traceback (innermost last): File "<string>", line 41, in ? com.hyperion.odi.common

  • GB2312 in SQL Server

    We just recently upgraded from ColdFusion 5 to CF8. We have some Chinese text stored in our SQL Server database in a text column in GB2312 format. We have been unable to output the text in CF8. To output the text in CF5, we just needed to use a <META

  • Presenter Notes Font - Default?

    I have to take notes on presentations in class regularly and I type them into the presenter notes. I'm having some trouble with the presenter notes' font and size. Everytime I go to a new slide's presenter notes, the font is Times New Roman or someth