BufferedImage 和 Graphics2D 画图,背景色透明

时间:2022-06-01 19:26:20
  File f = new File("D:\tag\20141204\chengxu\business-dossier\business-dossier-web\src\main\webapp\upload\2017-08-07\C7A23630C2700001FCD951071A601214.ico");
         ICOFile ico = new ICOFile(f.toURL());
         List list = ico.getImages();
         if(!list.isEmpty()){
             Image image = (Image) list.get(0);
             image = image.getScaledInstance(30, 30, Image.SCALE_SMOOTH); 
             BufferedImage bufimg = new BufferedImage(30,30,BufferedImage.TYPE_INT_RGB);
             Graphics2D g=bufimg.createGraphics();
             bufimg=g.getDeviceConfiguration().createCompatibleImage(30, 30,Transparency.TRANSLUCENT);
             g.dispose();
             g=bufimg.createGraphics();
             g.setColor(new Color(255,0,0));
             g.setStroke(new BasicStroke(1));
             g.drawImage(image, 0, 0, null);
             g.dispose();
             ImageIO.write(bufimg, "PNG", response.getOutputStream());

         }


aclibico-2.1.jar   自己下载