title: Convert JPG to PNG with background transparency
body: <p>While Converting from <strong>JPG to PNG</strong> background transparency Image , I don't want a dotted border at converted image</p>
  
  <p>My Original Image (JPG)
  <a href="https://i.stack.imgur.com/jEqbx.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/jEqbx.jpg" alt="My Original Image"></a></p>
  
  <p>My Converted Image (PNG)</p>
  
  <p><a href="https://i.stack.imgur.com/EqEaA.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/EqEaA.jpg" alt="enter image description here"></a></p>
  
  <p>My source code is </p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Graphics2D;
  import java.awt.Image;
  import java.awt.Toolkit;
  import java.awt.image.BufferedImage;
  import java.awt.image.FilteredImageSource;
  import java.awt.image.ImageFilter;
  import java.awt.image.ImageProducer;
  import java.awt.image.RGBImageFilter;
  import java.io.File;
  
  import javax.imageio.ImageIO;
  
  public class DemoTransparent {
  
      public static void main(String[] args) throws Exception {
  
          URL url = new URL("http://i.stack.imgur.com/jEqbx.jpg");
          Image  image1 = ImageIO.read(url);
          BufferedImage source = (BufferedImage) image1;
          int color = source.getRGB(0, 0);
          Image image = makeColorTransparent(source, new Color(color));
          BufferedImage transparent = imageToBufferedImage(image);
          File out = new File("D:\\Demo.png");
          ImageIO.write(transparent, "PNG", out);
  
      }
  
      private static BufferedImage imageToBufferedImage(Image image) {
  
          BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_4BYTE_ABGR_PRE);
  
          Graphics2D g2 = bufferedImage.createGraphics();
          g2.drawImage(image, 0, 0, null);
          g2.dispose();
          return bufferedImage;
  
      }
  
      public static Image makeColorTransparent(BufferedImage im, final Color color) {
          ImageFilter filter = new RGBImageFilter() {
  
              public int markerRGB = color.getRGB() | 0xFF000000;
              public final int filterRGB(int x, int y, int rgb) {
                  if ((rgb | 0xFF000000) == markerRGB) {
                      return 0x00FFFFFF &amp; rgb;
                  } else {
                      return rgb;
                  }
              }
  
  
          };
          ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
          return Toolkit.getDefaultToolkit().createImage(ip);
      }
  
  }
  </code></pre>
  
  <p>I want only png background transparency Image</p>