• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

rotate image java2d

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on a project where I need to rotate multiple images. I have no problem rotating the image multiple ways, but with affine transform the corners get cut off when rotating at weird angles, and if enlarge the size of the buffered image to remedy this, then the image size gets larger, although some of it is nonvisible space. does anyone know of any way to rotate an image with more control, i.e. getting down to the pixel level, and would this method allow me more control over the image rotation and painting?

thanks,
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How far have you got with your AffineTransform.
I haven't used it for some time, but as far as I remember, you can
  • rotate the Graphics2D object,
  • OR rotate the AffineTransform,
  • OR setToRotation on the AffineTransform.
  • As far as I remember, setToRotation() sets only one Transform, so any other transforms are lost.


    You can of course use the matrix formulae, which you will find on the API.

    CR
     
    Brandon Broschinsky
    Ranch Hand
    Posts: 41
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I have tried the first two methods, rotating the graphics object, and the rotating the transform. I just tried the setToRotation and it yielded the same results as rotating the transform. Basically the image is rotating but it draws the rotated image over the original in the same frame, if that makes sense?

    This is how I am doing it.

    private BufferedImage rotateImage(BufferedImage bi){
    Graphics2D g2d = bi.createGraphics();
    AffineTransform at = new AffineTransform();
    at.setToRotation(-Math.PI/15.0);
    g2d.drawImage(bi,at,this);
    g2d.transform(at);

    g2d.dispose();
    return bi;
    }

    I am passing in an image I have already drawn, and updating and repainting it.

    thanks,
     
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    hi iam new in Javaranch
     
    Campbell Ritchie
    Marshal
    Posts: 79153
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Does that work? That is the real question. "The proof of the pudding is in the eating."


    If not, try passing the Graphics (or graphics2D) object from your paintComponent() method to your rotateImage() method. Or clone the Graphics2D object and pass it to the rotateImage() method.

    If everything else works, and you are getting your image appearing twice: I presume you have super.paintComponent(); as the first line of your paintComponent() method? Try transforming the g2d object before you draw the image.

    CR
     
    When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic