图片上传都要使用输入流和输出流
inputStream is = null
outputSteam os = null
is = file.getInputStream();
保存文件信息
os= fileOutputStream("输出路径");
文件上传操作
创建字节数组
byte[] buff= new byte[1024];
int len= 0;
判断数组大小如果比0大的话,大于0的话,说明内容的,
while( (len=is.read(buff))>0){
os.writer(buff);
}
原图文件,相对路径,绝对路径共三个参数
file.getOriginalFilename();
1.使用一个开源类库,生成一个缩略图
Thunbnail.of(file.getInputStream()).size(WIDTH,HEIGHI).toFile("服务器路径");
2.使用AWT
定义一上输入流,把文件输入服务端
使用Image工具对原图进行读入和分析
Image ima = ImageIO.read(file.getInputStream());
获取原图的高度
宽度
定义一个缩略比例
宽度和高度
等比缩略,要进行计算,如果完缩比大于高缩比,取大的值
定义一个中间值wh=0;
if(width >hieght){
wh=with;
}else{
wh=hieght;
}
nWidth = 原图width/wh;
nHieght = 原图Hieght/wh;
获取一个缓存图片对象
bufferedImage buffIma=new BufferedImage(nWidth,nHieght,BufferedImage.Type_int_RGB)
buffIma.getGraphics().drawImage(image.getScaledInstance(nWith,nHieght,image.Scale_Smooth),0,0,null);
获取一个后缀名//image/jpeg 图像信息+图像类型
String imgType = file.getContextType().substring(file.getContext().indexOf("/")+1);
ImageIO.write(buffIma,imgType,os);
jsp页面
<img src=${pageContext.request.contextPath}${imageURL}/>
keepAspectRatio(false)不用进行等比缩略
inputStream is = null
outputSteam os = null
is = file.getInputStream();
保存文件信息
os= fileOutputStream("输出路径");
文件上传操作
创建字节数组
byte[] buff= new byte[1024];
int len= 0;
判断数组大小如果比0大的话,大于0的话,说明内容的,
while( (len=is.read(buff))>0){
os.writer(buff);
}
原图文件,相对路径,绝对路径共三个参数
file.getOriginalFilename();
1.使用一个开源类库,生成一个缩略图
Thunbnail.of(file.getInputStream()).size(WIDTH,HEIGHI).toFile("服务器路径");
2.使用AWT
定义一上输入流,把文件输入服务端
使用Image工具对原图进行读入和分析
Image ima = ImageIO.read(file.getInputStream());
获取原图的高度
宽度
定义一个缩略比例
宽度和高度
等比缩略,要进行计算,如果完缩比大于高缩比,取大的值
定义一个中间值wh=0;
if(width >hieght){
wh=with;
}else{
wh=hieght;
}
nWidth = 原图width/wh;
nHieght = 原图Hieght/wh;
获取一个缓存图片对象
bufferedImage buffIma=new BufferedImage(nWidth,nHieght,BufferedImage.Type_int_RGB)
buffIma.getGraphics().drawImage(image.getScaledInstance(nWith,nHieght,image.Scale_Smooth),0,0,null);
获取一个后缀名//image/jpeg 图像信息+图像类型
String imgType = file.getContextType().substring(file.getContext().indexOf("/")+1);
ImageIO.write(buffIma,imgType,os);
jsp页面
<img src=${pageContext.request.contextPath}${imageURL}/>
keepAspectRatio(false)不用进行等比缩略