Java - rotate -90°/90°


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public BufferedImage rotate90DX(BufferedImage bi)
  2. {
  3. int width = bi.getWidth();
  4. int height = bi.getHeight();
  5.  
  6. BufferedImage biFlip = new BufferedImage(height, width, bi.getType());
  7.  
  8. for(int i=0; i<width; i++)
  9. for(int j=0; j<height; j++)
  10. biFlip.setRGB(height-1-j, width-1-i, bi.getRGB(i, j));
  11.  
  12. return biFlip;
  13. }
  14.  
  15.  
  16. public BufferedImage rotate90SX(BufferedImage bi)
  17. {
  18. int width = bi.getWidth();
  19. int height = bi.getHeight();
  20.  
  21. BufferedImage biFlip = new BufferedImage(height, width, bi.getType());
  22.  
  23. for(int i=0; i<width; i++)
  24. for(int j=0; j<height; j++)
  25. biFlip.setRGB(j, i, bi.getRGB(i, j));
  26.  
  27. return biFlip;
  28. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.