如何正确保存透明照片?

  1. 我将透明图片保存为png格式。
  2. 通过单击打开照片。
  3. 片刻后消失。
  4. 图片不透明时不会发生此问题。
  5. 如何更改代码以避免此问题?

    class m extends JPanel{
        BufferedImage img = null;Graphics2D g2;
        @Override
        protected void paintComponent ( Graphics g ) {
            super.paintComponent ( g );
            try {      
                img= ImageIO.read(new File("C:\\Users\\Saulius\\Pictures\\Saved Pictures\\eifelis.png"));
                } catch (Exception e) {
                }  
        g2=(Graphics2D)g;
        tt();
        g2.drawImage(img,null);
        try {
    
            ImageIO.write(img,"png",new File("C:\\Users\\Saulius\\Desktop\\FOTke.png"));
    
        } catch (IOException ex) {}
        o=1;   
        }
        int o=0; int[][] px;
        void tt(){
            px=new int[img.getWidth()][img.getHeight()];
            for(int y =0; y < img.getHeight() ; y++)
                {
                    for (int x = 0; x < img.getWidth() ; x++) {
                        px[x][y]=img.getRGB(x,y);
                    }
                }
            img= new BufferedImage(img.getWidth(),img.getHeight(),BufferedImage.TYPE_INT_ARGB);
            for(int yy =0; yy < img.getHeight(); yy+=1)
                {
                int newy =(int) Math.ceil(Math.sin(Math.toRadians((yy+1)*(90.0/img.getHeight())))*(yy+1));
    
                for (int xx = 0; xx < img.getWidth() ; xx+=1) {
    
                    int newx =(int)Math.ceil(Math.sin(Math.toRadians((xx+1)*(90.0/img.getWidth())))*(xx+1)); 
                    float[]hsb=new float[4];
                    Color.RGBtoHSB(new Color(px[xx][newy-1]).getRed(),new Color(px[xx][newy-1]).getGreen(),new Color(px[xx][newy-1]).getBlue(),hsb);
                    Color c =new Color(px[xx][newy-1]);
                    img.setRGB(xx,yy,new Color(c.getRed(),c.getGreen(),c.getBlue(),50).getRGB());  
                }
            }
    
        }
    }
    

    enter image description here

dutacmdownload 回答:如何正确保存透明照片?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3095708.html

大家都在问