您的位置:首页 > 其它

两篇很牛的vim使用技巧

2015-03-02 16:29 295 查看
//newFilePath 表示图片存放的路径 w表示图片的原宽 h表示图片的原高
//inputStream 表示文件流
//压缩图片
public static boolean uploadJPGfile(InputStream inputStream,String newFilePath ,int w, int h) throws Exception {

int targetW = 700;
int targetH = 600;

double sx = (double)targetW/w;
double sy = (double)targetH/h;

if(sx < sy){
sx = sy;
targetW = (int)(sx * w);
}else{
sy = sx;
targetH = (int)(sy * h);
}
BufferedImage tag = new BufferedImage(targetW, targetH,
BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(ImageIO.read(inputStream), 0, 0, targetW, targetH, null);
FileOutputStream out = new FileOutputStream(newFilePath);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(tag);
out.close();
return true;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: