//
处理图片 处理图片公共方法
public
String posterImg(
byte
[] img, String type,String tb)
throws
Exception {
// 创建文件夹对象,参数文件夹地址
/* File file = new File("/store/image/100/356/", "poster"); */
Properties p = ConstVar.
PROPERS
;
File file =
new
File(p.getProperty(
"IMAGEPATH"
), tb);
if
(!file.exists()) {
// 判断目录是否存在
file.mkdirs();
// 创建目录
}
BufferedOutputStream bos;
// 定义输出流
// IdGenerator类-随机生成一组ID值
String idGerns = IdGenerator. createId();
String imgName = idGerns + type;
// 生成图片名称
String filePath = file.getPath() + File.
separator
;
// 得到filePath
filePath = filePath.replace(
"\\"
,
"/"
);
String fileName = filePath + imgName;
// 得到fileName
bos =
new
BufferedOutputStream(
new
FileOutputStream(fileName));
// 创建输出流
bos.write(img);
// 写到硬盘上
bos.close();
// 关闭输出流
// 处理图片
String littleName = filePath + idGerns +
"_little"
+ type;
// 生成商品小小图
String smallName = filePath + idGerns +
"_small"
+ type;
// 生成小图
String mediumName = filePath + idGerns +
"_medium"
+ type;
// 生成中图
String bigName = filePath + idGerns +
"_big"
+ type;
// 生成大图
ScaleImage is =
new
ScaleImage();
// 创建一个缩略图对象
String savePath = idGerns+type;
// 保存小图
try
{
Thumbnails. of(fileName).size(60, 60).toFile(littleName);
Thumbnails. of(fileName).size(100, 100).toFile(smallName);
Thumbnails. of(fileName).size(150, 150).toFile(mediumName);
Thumbnails. of(fileName).size(350, 350).toFile(bigName);
}
catch
(IOException e) {
e.printStackTrace();
}
return
savePath;
}