帮忙看看这是 什么程序 ~~~

simon1234567 simon1234567 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public void saveJPG(Image img, String s) {
BufferedImage bi = (BufferedImage) createImage(imgWidth, imgHeight);
/*
* BufferedImage bi = new BufferedImage( img.getWidth(null),
* img.getHeight(null), BufferedImage.TYPE_INT_RGB);
*/

Graphics2D g2 = bi.createGraphics();
g2.clipRect(rectX, rectY, rectWidth, rectHeight);
g2.drawImage(img, null, null);
int moveX = rectX > 0 ? rectX : 0;
int moveY = rectY > 0 ? rectY : 0;
int cutWidth = rectX + rectWidth > imgWidth ? rectWidth
- ((rectX + rectWidth) - imgWidth) : rectWidth;
int cutHeight = rectY + rectHeight > imgHeight ? rectHeight
- ((rectY + rectHeight) - imgHeight) : rectHeight;
bi = bi.getSubimage(moveX, moveY, cutWidth, cutHeight);

FileOutputStream out = null;
try {
out = new FileOutputStream(s);
} catch (java.io.FileNotFoundException io) {
System.out.println("File Not Found");
}
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(1f, false);
encoder.setJPEGEncodeParam(param);
try {
encoder.encode(bi);
out.close();
} catch (java.io.IOException io) {
System.out.println("IOException");
}
}
...全文
评论 1
收藏 已收藏
分享
返回顶部
simon1234567
非技术区 23,404 成员 70,506 内容