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 ]");
}
11-19
3498
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)