title: How to make smooth blur effect in java?
body: <p>I have blured an image. But it is not smooth. </p>
  
  <p>I heard that if I use the gaussian blur technique then I can remove the box effect. </p>
  
  <p>But I don't know how to implement it with my code (I did some random technique but it messes with the color). Can you suggest me how to do gaussian blur with my code?</p>
  
  <pre><code>public class BlurImageDemo {
  
  Color c[];
  
  BlurImageDemo() throws IOException, InterruptedException {
      File f = new File("D:\\x.jpg");
      BufferedImage im = ImageIO.read(f);
  
      BufferedImage bi = new BufferedImage(im.getWidth(), im.getHeight(), BufferedImage.TYPE_INT_RGB);
      int i = 0;
      int max = 400, radius = 10;
      int a1 = 0, r1 = 0, g1 = 0, b1 = 0;
      c = new Color[max];
      int x = 1, y = 1, x1, y1, ex = 5, d = 0;
      for (x = radius; x &lt; im.getHeight() - radius; x++) {
          for (y = radius; y &lt; im.getWidth() - radius; y++) {
  
              //20x20 matrix
              for (x1 = x - radius; x1 &lt; x + radius; x1++) {
                  for (y1 = y - radius; y1 &lt; y + radius; y1++) {
                      c[i++] = new Color(im.getRGB(y1, x1));
                      //System.out.println(i);
                  }
              }
              i = 0;
  
              for (d = 0; d &lt; max; d++) {
                  a1 = a1 + c[d].getAlpha();
              }
              a1 = a1 / (max);
  
              for (d = 0; d &lt; max; d++) {
                  r1 = r1 + c[d].getRed();
              }
              r1 = r1 / (max);
  
              for (d = 0; d &lt; max; d++) {
                  g1 = g1 + c[d].getGreen();
              }
              g1 = g1 / (max);
  
              for (d = 0; d &lt; max; d++) {
                  b1 = b1 + c[d].getBlue();
              }
              b1 = b1 / (max);
              int sum1 = (a1 &lt;&lt; 24) + (r1 &lt;&lt; 16) + (g1 &lt;&lt; 8) + b1;
              bi.setRGB(y, x, (int) (sum1));
  
          }
      }
      ImageIO.write(bi, "jpg", new File("D:\\x1.jpg"));
  }
  
  public static void main(String[] args) throws IOException, InterruptedException {
      new BlurImageDemo();
  }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/UlkfL.jpg" alt="this is the final image, which is not smooth"></p>