Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java从图像中去除白色矩形_Java - Fatal编程技术网

如何使用java从图像中去除白色矩形

如何使用java从图像中去除白色矩形,java,Java,我已经厌倦了下面的代码来生成缩略图,但是当我把它放在另一个图像上时,缩略图有一个白色的矩形。如何使用java graphics 2D删除它 Image image = javax.imageio.ImageIO.read(new File(originalFile)); BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB); Gr

我已经厌倦了下面的代码来生成缩略图,但是当我把它放在另一个图像上时,缩略图有一个白色的矩形。如何使用java graphics 2D删除它

  Image image = javax.imageio.ImageIO.read(new File(originalFile));       
  BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
  Graphics2D graphics2D = thumbImage.createGraphics();
  graphics2D.setBackground(Color.WHITE);
  graphics2D.setPaint(Color.WHITE); 
  graphics2D.fillRect(0, 0, thumbWidth, thumbHeight);       
  graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);   
  File file = new File(thumbnailFile);
  if(javax.imageio.ImageIO.write(thumbImage, "png", file))
      return file;
  }
即使我去掉这三条线,我也会得到一个黑色的矩形

 graphics2D.setBackground(Color.WHITE);
 graphics2D.setPaint(Color.WHITE); 
 graphics2D.fillRect(0, 0, thumbWidth, thumbHeight);   
如何使此图像透明?请找个人帮我

 Color transparent = new Color(0,0,0,0)
通过设置组合:

通过设置组合:

这应该是:

..BufferedImage.TYPE_INT_ARGB
这应该是:

..BufferedImage.TYPE_INT_ARGB

图形2d.倒退(新颜色(0,0,0,0));graphics2D.setPaint(新颜色(0,0,0,0));graphics2D.fillRect(0,0,拇指宽度,拇指高度);图形2d.倒退(新颜色(0,0,0,0));graphics2D.setPaint(新颜色(0,0,0,0));graphics2D.fillRect(0,0,拇指宽度,拇指高度);图形2d.倒退(新颜色(0,0,0,0));graphics2D.setPaint(新颜色(0,0,0,0));graphics2D.fillRect(0,0,拇指宽度,拇指高度);当我放置在另一个图像上时,仍然得到了白色矩形。graphics2D.setBackground(新颜色(0,0,0,0));graphics2D.setPaint(新颜色(0,0,0,0));graphics2D.fillRect(0,0,拇指宽度,拇指高度);当我放置在另一个图像上时,仍然得到了白色矩形。
..BufferedImage.TYPE_INT_ARGB