图片.txt
来自「收集到的一些J2ME资料。。 包括图片的角度翻转。。A*算法和一些其他文章」· 文本 代码 · 共 55 行
TXT
55 行
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class DisposeIMG {
public DisposeIMG() {
}
public static String getFixedBoundIcon(String filePath, int height,
int width) {
double Ratio = 0.0; // 缩放比例
File F = new File(filePath);
if (!F.isFile()) {
return " is not image file error in getFixedBoundIcon!";
}
BufferedImage Bi = null;
try {
Bi = ImageIO.read(F);
} catch (IOException ex1) {
return "read error!";
}
if ((Bi.getHeight() > height) || (Bi.getWidth() > width)) {
if (Bi.getHeight() > Bi.getWidth()) {
Ratio = (new Integer(height)).doubleValue() / Bi.getHeight();
} else {
Ratio = (new Integer(width)).doubleValue() / Bi.getWidth();
}
File ThF = new File(filePath + "_" + height + "_" + width);
Image Itemp = Bi.getScaledInstance(width, height,
BufferedImage.SCALE_SMOOTH);
AffineTransformOp op = new AffineTransformOp(AffineTransform
.getScaleInstance(Ratio, Ratio), null);
Itemp = op.filter(Bi, null);
try {
ImageIO.write((BufferedImage) Itemp, "jpg", ThF);
} catch (Exception ex) {
return "错误";
}
}
return "修改成功";
}
public static void main(String[] atge) {
System.out.println(DisposeIMG.getFixedBoundIcon("F:/20057.jpg", 166,
132));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?