现在要实现一种功能
比发上传一张图片,大小有1M,尺寸也很大/
现在想要一个class文件,把上传的图片,自动裁成固定的大小,比如800*600,一百来K这样.
谁开发过这种例子?或看到过.
救助了,
比发上传一张图片,大小有1M,尺寸也很大/
现在想要一个class文件,把上传的图片,自动裁成固定的大小,比如800*600,一百来K这样.
谁开发过这种例子?或看到过.
救助了,
解决方案 »
- spring 配置问题 No Scope registered for scope 'singletone'救命啊
- input 失去焦点的问题
- 前贴已结,再开一贴重新发问,SQLSever2000 Driver for JDBC Error establishing socket ,心里着急,万分感谢
- JSP翻页问题
- 快捷键问题
- session失效怎么用监听器来实现
- 请教简单jsp问题
- 请问这几句话是什么意思?
- 请教:如何实现在页面上浮动的flash动画?
- TOMCAT的日志可以象IIS一样详细吗?
- 在Jsp中或Struts中怎麼創建錯誤處理頁面??????
- 如何获得建立数据库连接所用的时间 SQLSERVER JDBC
* 等比例缩放图像, 本方法目前支持三个图片格式jpg, gif, png, 所有生成都被转化为jpg
*fullname 图片路径
* path 目标路径(不带文件名)
*prtfix 生成的文件名的前缀
*photomaxw 文件宽度范围
*photomaxh 文件高度范围
*/
public static String getSmallJpg(String fullname, String path, String prefix,
float photomaxw, float photomaxh) throws
Exception {
File filePath = null;
try {
File file = new File(fullname); //读入文件
if (!file.exists()) {
return null;
}
else {
//上传flash
if (fullname.endsWith("swf")) {
String fileName = file.getName();
String filePiexName = FileUtil.getFilePrefixName(fileName);
String newPmgPath = path + "/" + prefix + "_" + filePiexName + ".swf";
FileUtil.copyFile(fullname, newPmgPath);
File newFile = new File(newPmgPath);
return newFile.getName();
}
} Image src = javax.imageio.ImageIO.read(file); //构造Image对象
// System.out.println("压缩文件名:" + " " + file.getAbsoluteFile() );
float wideth = src.getWidth(null); //得到源图宽
float height = src.getHeight(null); //得到源图长
System.out.println("class = " + src.getClass()); System.out.println("源文件宽度:" + wideth + "¥"); //测试
System.out.println("源文件高度:" + height + "¥"); if (wideth > photomaxw) {
float mw = wideth;
System.out.println("限制高度:" + photomaxh);
System.out.println("限制宽度:" + photomaxw);
wideth = photomaxw;
height = height * photomaxw / mw; System.out.println("收缩后的实际宽度:" + wideth + "●"); //测试
System.out.println("收缩后的实际高度:" + height + "●"); if (height > photomaxh) {
float mo = height;
height = photomaxh;
wideth = wideth * photomaxh / mo;
}
}
else if (wideth < photomaxw || wideth == photomaxw) {
float mo = height;
if (height > photomaxh) {
height = photomaxh;
wideth = wideth * height / mo;
}
} if (wideth == 0) {
wideth = src.getWidth(null);
} if (height == 0) {
height = src.getHeight(null);
} System.out.println("最终宽度:" + wideth + "●"); //测试
System.out.println("最终高度:" + height + "●"); if (height == 0 || wideth == 0) {
return null;
} BufferedImage tag = new BufferedImage( (int) wideth, (int) height,
BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src, 0, 0, (int) wideth, (int) height, null); //绘制后的图 String fileName = file.getName(); File newPmgPathDir = new File(path);
if (!newPmgPathDir.exists() || !newPmgPathDir.isDirectory()) {
newPmgPathDir.mkdirs();
} String filePiexName = FileUtil.getFilePrefixName(fileName);
String newPmgPath = path + "/" + prefix + "_" + filePiexName + ".jpg"; FileOutputStream out = new FileOutputStream(newPmgPath); //输出到文件流
System.out.println("getParent:" + file.getParent());
System.out.println("getAbsoluteFile:" + file.getAbsoluteFile());
System.out.println("getAbsolutePath:" + file.getAbsolutePath());
System.out.println("getCanonicalFile:" + file.getCanonicalFile());
System.out.println("getCanonicalPath:" + file.getCanonicalPath()); //有什么区别????
//// System.out.println("生成的文件名为:" + newPmgPath); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(tag);
out.close(); filePath = new File(newPmgPath); //读入文件
System.out.println("getAbsoluteFile:" + newPmgPath);
}
catch (Exception ex) {
ex.printStackTrace();
}
return filePath.getName();
}
http://truemag.qq.com/engine/isapi/frame.dll?bc=4226&co=nfrwzk&gp=18&ul=zh-cn
这样,速度要像这么快,缓存里保存的不是一张大图片,而是十二张小图片.
客户的意思是这样哎,真的要苦笑了,我都会开发frame.dll这样的啦,我也去QQ啦