title: Supersampling implementation for high quality downscaling
body: <p>I want to create down-scaled Bitmaps ( original Bitmap loaded from asset) with high quality comparable to the quality of bitmaps scaled with professional software like Paint.net (in Paint.NET the algorithm for scaling is choosen in a field called Interpolation. The highest setting uses supersampling)?</p>
  
  <p>I understand how to implement supersampling for anti-aliasing. For anti-aliasing-purpose the original image is rendered in higher resolution and then gets downsampled. For Example to get a target image of 100x100 you would render the scene to 200x200 and then downsampling it with a 2x2 grid. </p>
  
  <p>But, how the algorithm can handle downsampling from let's say 400x400 to 175x175 for scaling-purpose. The grid must be ~ 2.285x2.285 in this case. So how can supersampling be implemented for scaling-purpose?</p>
  
  <p>thx </p>
  
  <p>EDIT:
  My current algorithm looks like this:</p>
  
  <pre><code>private Bitmap downscale(Bitmap src, int targetWidth, int targetHeight){
      Bitmap target = Bitmap.createBitmap(targetWidth, targetHeight, Config.ARGB_8888);
      float w = src.getWidth()/(float)targetWidth;
      float s = src.getHeight()/(float)targetHeight;
      int color = 0;
      int g = 0;
      for(int i=0;i&lt;target.getWidth();++i){
          for(int j=0;j&lt;target.getHeight();++j){
              color = 0;
              g = 0;
              for(float k =i*w;k&lt;roundUp((i+1)*w);++k){
                  for(float l=j*w;l&lt;roundUp((j+1)*s);++l){
                      ++g;
                      color+=src.getPixel((int)k, (int)l);
                  }
              }
              target.setPixel(i, j, color/g);
          }
      }
      return target;
  </code></pre>
  
  <p>}</p>
  
  <p>The image shows the same 100x100 bitmap scaled to 54x54. The left one is scaled by Paint.Net and the right one by my algorithm. Doesn't look good... How can I improve my code?</p>