📄 imagebean.java
字号:
package com.sunnitech.bean;
import com.jspsmart.upload.SmartUpload;
import com.sunnitech.Image.ImageConvertor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class ImageBean {
public static boolean Convert(SmartUpload myupload, String path, int fCount) throws IOException {
boolean isOK = false;
FileInputStream fin1 = null;
FileInputStream fin2 = null;
FileOutputStream fout = null;
FileOutputStream fout_m = null;
try {
for(int i = 0; i < fCount; i++) {
isOK = false;
String oldpath = path + myupload.getFiles().getFile(i).getFileName();
String newpath = oldpath;
String mobilepath = oldpath;
String renamepath = oldpath;
int pos = newpath.lastIndexOf(".");
newpath = newpath.substring(0, pos) + "_new.jpg";
mobilepath = mobilepath.substring(0, pos) + "_m.jpg";
renamepath = renamepath.substring(0, pos) + ".jpg";
fin1 = new FileInputStream(oldpath);
fin2 = new FileInputStream(oldpath);
fout = new FileOutputStream(newpath);
fout_m = new FileOutputStream(mobilepath);
ImageConvertor.converScale(fin1, fout, 640, 480, 1F);
ImageConvertor.converScale(fin2, fout_m, 128, 128, 1F);
fin1.close();
fin2.close();
fout.close();
fout_m.close();
// ReName
File myoldfile = new File(oldpath);
File mynewfile = new File(newpath);
if(myoldfile.delete()) {
mynewfile.renameTo(new File(renamepath));
isOK = true;
}
}
} catch(Exception e) {
System.out.println("image bean err: " + e.getMessage());
return false;
} finally {
if(fin1 != null) {
fin1.close();
}
if(fin2 != null) {
fin2.close();
}
if(fout != null) {
fout.close();
}
if(fout_m != null) {
fout_m.close();
}
}
return isOK;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -