java 切图
public boolean scaleImageFromUrl(String oldpath, String newpath, int wdith,
int height) {
try {
URL url = null;
url = new URL(oldpath);
URLConnection connection;
connection = url.openConnection();
BufferedImage bi = ImageIO.read(connection.getInputStream());
Image Itemp = bi.getScaledInstance(wdith, height,
BufferedImage.SCALE_SMOOTH);
BufferedImage thumbnail = new BufferedImage(wdith, height,
BufferedImage.TYPE_INT_RGB);
thumbnail.getGraphics().drawImage(Itemp, 0, 0, null);
File newimg = new File(newpath);
FileOutputStream out = new FileOutputStream(newimg);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder
.getDefaultJPEGEncodeParam(thumbnail);
param.setQuality(1.0f, false);
encoder.encode(thumbnail);
out.close();
bi.flush();
bi = null;
return true;
} catch (IOException e) {
return false;
}
}
public boolean scaleImageFromUrl(String oldpath, String newpath, int wdith) {
try {
int height=367;
URL url = null;
url = new URL(oldpath);
URLConnection connection;
connection = url.openConnection();
BufferedImage bi = ImageIO.read(connection.getInputStream());
if(bi.getWidth()<=550){
wdith=bi.getWidth();
height=bi.getHeight();
}else{
height=(int)Math.floor(wdith*bi.getHeight()/bi.getWidth());
}
Image Itemp = bi.getScaledInstance(wdith, height,
BufferedImage.SCALE_SMOOTH);
BufferedImage thumbnail = new BufferedImage(wdith, height,
BufferedImage.TYPE_INT_RGB);
thumbnail.getGraphics().drawImage(Itemp, 0, 0, null);
File newimg = new File(newpath);
FileOutputStream out = new FileOutputStream(newimg);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder
.getDefaultJPEGEncodeParam(thumbnail);
param.setQuality(0.8f, false);
encoder.encode(thumbnail);
out.close();
bi.flush();
bi = null;
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
分享到:
相关推荐
im4java切图
Java写切图源码,Java写切图源码, Java写切图源码
java 图片处理 切图代码 实现自动缩放图片
切图工具切图工具切图工具
切图切图切图切图1111
这是一个切图工具类(内含一个方法),前端可配合使用jQuery、Jcrop,jQuery就不用说了,Jcrop相关资料可参考官网,其他业务请根据实际需求进行编写。
天地图切图比例尺,
ps网站切图、网页切图教程详解 ps网站切图、网页切图教程详解 ps网站切图、网页切图教程详解
不用安装直接切图不用安装直接切图不用安装直接切图不用安装直接切图
一个完整的图片上传剪切图像功能,而且是java版本,下了不后悔,
UI切图命名规范,好的规范,能提高质量和效率
切图+更新包
最好用的ps切图工具,最好用的ps切图工具最好用的ps切图工具最好用的ps切图工具最好用的ps切图工具最好用的ps切图工具
div+css 切图实例div+css 切图实例div+css 切图实例div+css 切图实例div+css 切图实例div+css 切图实例div+css 切图实例div+css 切图实例
怎么切图.pdf 怎么切图.pdf 怎么切图.pdf 怎么切图.pdf 怎么切图.pdf
切图div+css
通话界面手机按钮图标
栅格地图切图工具及栅格图片转换工具使用说明文档.pdf )
批量切图软件是专为网店卖家精心设计的一款切图软件,解决了网站卖家切图难、重复性工作量大的问题。它可以一次针对多张照片,根据设定的块数或大小进行一键切图,切好的图自动保存到指定的目录下,简单实用。使用本...
GIS坐标、投影、切图