title: Cropping image lowers quality and border looks bad
body: <p>Using some math, i created the following java-function, to input a Bitmap, and have it crop out a centered square in which a circle is cropped out again with a black border around it.
  The rest of the square should be transparent.
  Additionatly, there is a transparent distance to the sides to not damage the preview when sending the image via Messengers.</p>
  
  <p>The code of my function is as following:</p>
  
  <pre><code> public static Bitmap edit_image(Bitmap src,boolean makeborder) {
          int width = src.getWidth();
          int height = src.getHeight();
          int A, R, G, B;
          int pixel;
  
          int middlex = width/2;
          int middley = height/2;
  
          int seitenlaenge,startx,starty;
          if(width&gt;height) 
          {
              seitenlaenge=height;
              starty=0;
  
              startx = middlex - (seitenlaenge/2);
          }
          else 
          {
              seitenlaenge=width; 
              startx=0;
  
              starty = middley - (seitenlaenge/2);
          }
  
          int kreisradius = seitenlaenge/2;
          int mittx = startx + kreisradius;
          int mitty = starty + kreisradius;
          int border=2;
          int seitenabstand=55;
  
          Bitmap bmOut = Bitmap.createBitmap(seitenlaenge+seitenabstand, seitenlaenge+seitenabstand, Bitmap.Config.ARGB_8888);
          bmOut.setHasAlpha(true);
  
          for(int x = 0; x &lt; width; ++x) {
              for(int y = 0; y &lt; height; ++y) {
                  int distzumitte = (int) (Math.pow(mittx-x,2) + Math.pow(mitty-y,2)); // (Xm-Xp)^2 + (Ym-Yp)^2 = dist^2
                  distzumitte = (int) Math.sqrt(distzumitte);
  
                  pixel = src.getPixel(x, y);
  
                  A = Color.alpha(pixel);
                  R = (int)Color.red(pixel);
                  G = (int)Color.green(pixel);
                  B = (int)Color.blue(pixel);
                  int color = Color.argb(A, R, G, B);
  
                  int afterx=x-startx+(seitenabstand/2);
                  int aftery=y-starty+(seitenabstand/2);
  
                  if(x &lt; startx || y &lt; starty || afterx&gt;=seitenlaenge+seitenabstand || aftery&gt;=seitenlaenge+seitenabstand) //seitenrand
                  {
                      continue;
                  }
                  else if(distzumitte &gt; kreisradius)
                  {
                      color=0x00FFFFFF;
                  }
                  else if(distzumitte &gt; kreisradius-border &amp;&amp; makeborder) //border
                  {
                      color = Color.argb(A, 0, 0, 0);
                  }
                  bmOut.setPixel(afterx, aftery, color);
              }
          }
  
          return bmOut;
      }
  </code></pre>
  
  <p>This function works fine, but there are some problems occuring that i wasn't able to resolve yet.</p>
  
  <ul>
  <li>The quality of the image is decreased significantly</li>
  <li>The border is not really round, but appears to be flat at the edges of the image (on some devices?!)</li>
  </ul>
  
  <p>I'd appreciate any help regarding that problems. I got to admit that i'm not the best in math and there should probably be a better formula to ceate the border.</p>