public Object rotate(Object image,int degrees){
  int width=getImageWidth(image);
  int height=getImageHeight(image);
  int[] arr=new int[width * height];
  int[] dest=new int[arr.length];
  getRGB(image,arr,0,0,0,width,height);
  int centerX=width / 2;
  int centerY=height / 2;
  double radians=Math.toRadians(-degrees);
  double cosDeg=Math.cos(radians);
  double sinDeg=Math.sin(radians);
  for (int x=0; x < width; x++) {
    for (int y=0; y < height; y++) {
      int x2=round(cosDeg * (x - centerX) - sinDeg * (y - centerY) + centerX);
      int y2=round(sinDeg * (x - centerX) + cosDeg * (y - centerY) + centerY);
      if (!(x2 < 0 || y2 < 0 || x2 >= width || y2 >= height)) {
        int destOffset=x2 + y2 * width;
        if (destOffset >= 0 && destOffset < dest.length) {
          dest[x + y * width]=arr[destOffset];
        }
      }
    }
  }
  return createImage(dest,width,height);
}

public Object rotate ( Object image , int degrees ) { int width = getImageWidth ( image ) ; int height = getImageHeight ( image ) ; int [ ] arr = new int [ width * height ] ; int [ ] dest = new int [ arr . length ] ; getRGB ( image , arr , 0 , 0 , 0 , width , height ) ; int centerX = width / 2 ; int centerY = height / 2 ; double radians = Math . toRadians ( - degrees ) ; double cosDeg = Math . cos ( radians ) ; double sinDeg = Math . sin ( radians ) ; for ( int x = 0 ; x < width ; x ++ ) { for ( int y = 0 ; y < height ; y ++ ) { int x2 = round ( cosDeg * ( x - centerX ) - sinDeg * ( y - centerY ) + centerX ) ; int y2 = round ( sinDeg * ( x - centerX ) + cosDeg * ( y - centerY ) + centerY ) ; if ( ! ( x2 < 0 || y2 < 0 || x2 >= width || y2 >= height ) ) { int destOffset = x2 + y2 * width ; if ( destOffset >= 0 && destOffset < dest . length ) { dest [ x + y * width ] = arr [ destOffset ] ; } } } } return createImage ( dest , width , height ) ; }
returns an instance of this image rotated by the given number of degrees . by default 90 degree angle divisions are supported , anything else is implementation dependent . this method assumes a square image . notice that it is inefficient in the current implementation to rotate to non - square angles , < p > e . g . rotating an image to 45 , 90 and 135 degrees is inefficient . use rotatate to 45 , 90 and then rotate the 45 to another 90 degrees to achieve the same effect with less memory .
