去掉或者合成水印

public static  void RemoveTex(CubismModel model,int index) throws IOException {
        //先备份一下数据
        String inputFile="";
        if(model.getDrawableViews()[index].getTextureIndex() == 0){
            inputFile=ConfigPath.m_InPathTex+"texture_00.png";
            File file = new File(ConfigPath.m_InPathTex+"备份");
            if(!file.exists()){
                file.mkdir();
            }
            //备份过就不备份了
            File file2 = new File(ConfigPath.m_InPathTex+"备份\\texture_00.png");
            if(!file2.exists()){
                Files.copy(Path.of(ConfigPath.m_InPathTex + "texture_00.png"), Path.of(ConfigPath.m_InPathTex + "备份\\texture_00.png"));
            }
            inputFile= ConfigPath.m_InPathTex+"备份\\texture_00.png";
        }else{
            return;
        }
        BufferedImage image = ImageIO.read(new File(inputFile));
        List<Point2D.Float> ptPolygon =  Coordinate.getTexUsvScreenPoint(model,index);
        Rect rect =new Rect(ptPolygon);
        int width= rect.getPixWidth(image.getWidth());
        int height=rect.getPixHeight(image.getHeight());
        if(width == 0 && height == 0){
            width =1;
            height = 1;
        }
        //BufferedImage img = new BufferedImage(width, height, image.getType());
        int indexLeft = (int) (rect.getLeft()*image.getWidth());
        int indexBottom = (int) ((1 - rect.getBottom())*image.getWidth());
        if(width == 1&& height == 1){
            int rgb = image.getRGB(indexLeft,indexBottom);
            //img.setRGB(0,0,rgb);
        }else{
            for (int x = 0 ;x < width;x++){
                for (int y = 0 ;y < height;y++){
                    int srcWidth = (indexLeft+x);
                    int srcHeight = (indexBottom+y);
                    //进行坐标系变换
                    float oryW=( (image.getWidth() * rect.getLeft())+x) / image.getWidth();
                    float oryH=1-( ((1 - rect.getBottom())*image.getWidth()+y) / image.getWidth());
                    Point2D.Float point = new Point2D.Float( oryW,oryH );
                    //怎么判断点在多边形里面
                    int pixelData = 0;
                    if(Coordinate.checkWithJdkGeneralPath(ptPolygon,point)){
                        image.setRGB(srcWidth,srcHeight,0);
                    }else{
                        //pixelData = image.getRGB(srcWidth,srcHeight);//平移变换
                    }
                    //img.setRGB(x,y,pixelData);
                }
            }

        }

        boolean success = ImageIO.write(image, "png", new File(inputFile));
        System.out.println(success ? "[ SUCCESS ]" : "[ FAILURE ]");

    }
    public static  void Repalce(CubismModel model,int index,String out) throws IOException {
        //先备份一下数据
        String inputFile="";
        //
        if(model.getDrawableViews()[index].getTextureIndex() == 0){
            inputFile=ConfigPath.m_InPathTex+"texture_00.png";
            File file = new File(ConfigPath.m_InPathTex+"备份");
            if(!file.exists()){
                file.mkdir();
            }
            //备份过就不备份了
            File file2 = new File(ConfigPath.m_InPathTex+"备份\\texture_00.png");
            if(!file2.exists()){
                Files.copy(Path.of(ConfigPath.m_InPathTex + "texture_00.png"), Path.of(ConfigPath.m_InPathTex + "备份\\texture_00.png"));
            }
            inputFile= ConfigPath.m_InPathTex+"备份\\texture_00.png";
        }else{
            return;
        }
        BufferedImage image = ImageIO.read(new File(inputFile));
        BufferedImage outImage = ImageIO.read(new File(out));
        List<Point2D.Float> ptPolygon =  Coordinate.getTexUsvScreenPoint(model,index);
        Rect rect =new Rect(ptPolygon);
        int width= rect.getPixWidth(image.getWidth());
        int height=rect.getPixHeight(image.getHeight());
        if(width == 0 && height == 0){
            width =1;
            height = 1;
        }
        //BufferedImage img = new BufferedImage(width, height, image.getType());
        int indexLeft = (int) (rect.getLeft()*image.getWidth());
        int indexBottom = (int) ((1 - rect.getBottom())*image.getWidth());
        if(width == 1&& height == 1){
            int rgb = image.getRGB(indexLeft,indexBottom);
            //img.setRGB(0,0,rgb);
        }else{
            for (int x = 0 ;x < width;x++){
                for (int y = 0 ;y < height;y++){
                    int srcWidth = (indexLeft+x);
                    int srcHeight = (indexBottom+y);
                    //进行坐标系变换
                    float oryW=( (image.getWidth() * rect.getLeft())+x) / image.getWidth();
                    float oryH=1-( ((1 - rect.getBottom())*image.getWidth()+y) / image.getWidth());
                    Point2D.Float point = new Point2D.Float( oryW,oryH );
                    //怎么判断点在多边形里面
                    int pixelData = 0;
                    if(Coordinate.checkWithJdkGeneralPath(ptPolygon,point)){
                        int rgb = outImage.getRGB(x,y);
                        image.setRGB(srcWidth,srcHeight,rgb);
                    }else{
                        //pixelData = image.getRGB(srcWidth,srcHeight);//平移变换
                    }
                    //img.setRGB(x,y,pixelData);
                }
            }

        }

        boolean success = ImageIO.write(image, "png", new File(inputFile));
        System.out.println(success ? "[ SUCCESS ]" : "[ FAILURE ]");


    }
    

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值