title: Java Image Rotation does not work properly
body: <p>Hello fellow programmers,</p>
  
  <p>I am making a game and I want to be able to rotate my images.
  I dont use Graphics2d because i made the render class myself(Mostly).</p>
  
  <p>The problem is that my current rotation method leaves holes in the new (rotated) picture it also does not place the new pixels on the right spot...</p>
  
  <p>I dont see the problem so maybe you can help :)</p>
  
  <pre><code>    public void drawRotatedImage(Image image, int offX, int offY, double degree){
      int Iwidth = image.width;
      int Iheight = image.height;
  
      double angle = Math.toRadians(degree);
      double sin = Math.sin(angle);
      double cos = Math.cos(angle);
      double x0 = 0.5 * (Iwidth  - 1);     // point to rotate about
      double y0 = 0.5 * (Iheight - 1);     // center of image
  
      for(int x = 0; x &lt; Iwidth; x++){
          for(int y = 0; y &lt; Iheight; y++){
              double a = x - x0;
              double b = y - y0;
              int xx = (int) (+a * cos - b * sin + x0);
              int yy = (int) (+a * sin + b * cos + y0);
  
              if(xx &gt;= 0 &amp;&amp; xx &lt; width &amp;&amp; yy &gt;= 0 &amp;&amp; yy &lt; height){
                  setPixel(x+offX, y+offY, image.pixels[xx + yy*image.width]);
              }
          }
      }
  }
  </code></pre>
  
  <p>the setpixel function looks like this:</p>
  
  <pre><code> public void setPixel(int x, int y, int color){
      if((x &lt; 0 || x &gt;= width || y &lt; 0 || y &gt;= height) || color == 0xffff00ff){
          return;
      }
      pixels[x + y * width] = color;
  
  
  }
  </code></pre>
  
  <p>This works fine for non rotated images... but when i rotate it gives weird shit
  Except when i use an perfect square as image and then rotate like 90 or 180
  But otherwise i get back images full of holes and wrong pixels....</p>
  
  <p>So to be clear it is not a bug or something like that... im just on the lookout for a better solution or something to fill the holes.</p>