public static void convert(File dir) throws IOException {
File[] files = dir.listFiles();
File a=new File("D:/result/");
for(int ifile = 0; ifile < files.length; ifile++) {
if(files[ifile].isDirectory()) {
convert(files[ifile]);
continue;
}
String fileName = files[ifile].getAbsolutePath();
if(!".png".equals(fileName.substring(fileName.length() - 4))) {
continue;
}
System.out.println("转换:" + files[ifile].getAbsolutePath());
File aa=new File("D:/test/bed.png");
FileInputStream fileIn = new FileInputStream(aa);
// BufferedImage sourceImg=ImageIO.read(files[ifile]);
byte[] pngBytes = convertPng(fileIn, (byte)0xff, (byte)0, (byte)0xff);
fileIn.close();
if(pngBytes == null) {
System.out.println(files[ifile].getAbsolutePath());
continue;
}
FileOutputStream fileOut = new FileOutputStream(a);
fileOut.write(pngBytes, 0, pngBytes.length);
fileOut.close();
}
}