Java压缩模型贴图
package makeimg;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Mains {
public static BufferedImage resize(BufferedImage img, int newW, int newH) {
int w = img.getWidth();
int h = img.getHeight();
BufferedImage dimg = new BufferedImage(newW, newH, img.getType());
Graphics2D g = dimg.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);
g.dispose();
return dimg;
}
public static void main(String[] args) {
if(args.length!=1)
return;
try {
FileInputStream ini=new FileInputStream("1.txt");
byte t[]=new byte[1024];
int length=ini.read(t);
ini.close();
String Le=new String(t,0,length);
System.out.println(Le);
length=Integer.valueOf(Le);
BufferedImage img=ImageIO.read(new File(args[0]));
String houz=args[0].substring(args[0].length()-3);
int w=img.getWidth();
int h=img.getHeight();
float dpi=1;
if(w>h)
{
h=(int)(((float)h/w)*length);
w=length;
}
else
{
w=(int)(((float)w/h)*length);
h=length;
}
System.out.println(w+" "+h);
BufferedImage out=resize(img,w,h);
img.flush();
ImageIO.write(out, houz, new File(args[0]));
} catch (IOException e) {
e.printStackTrace();
}
}
}