站内搜索: 请输入搜索关键词

当前页面: 开发资料首页JSP 专题求救一种技术,高手进来看一看啊

求救一种技术,高手进来看一看啊

摘要: 求救一种技术,高手进来看一看啊


现在要实现一种功能
比发上传一张图片,大小有1M,尺寸也很大/
现在想要一个class文件,把上传的图片,自动裁成固定的大小,比如800*600,一百来K这样.
谁开发过这种例子?或看到过.
救助了,


java 2d api


楼上的有没有例子啊


上传后,设置缩放,java2d的缓冲image有这功能


楼上两位兄弟,感谢是很感谢,但有没有实例,我这个是新手,麻烦了麻烦了,


估计难,要是1M的东西搞成100K的话就要看图片的格式了


只是例子只是例子,文件大小倒其次,只要把大小裁好就好了


/**
* 等比例缩放图像, 本方法目前支持三个图片格式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();
}


我写的代码,呵呵,你用一下试试,


如果成功的话,要多给分啊,你的分太少了


嗯,这个是我倾家荡产了.
完了,那个客户要求又变了,
要一张大图片,切成十二张小图片,然后拼成一个大图片.这个有办法吗?


呵呵,我现在只有苦笑了,客户真会跟我开玩笑


保存还得保存在一大张,不能变成一小张


没有比例缩小的要求吗,那还切什么啊,直接复制那个图片就可以了




其实有的时候客户的要求也不是去对的,你应该和他们解释一下,我们不能无休止的满足客户的一切需要


进mag.qq.com

就像
http://truemag.qq.com/engine/isapi/frame.dll?bc=4226&co=nfrwzk&gp=18&ul=zh-cn
这样,速度要像这么快,缓存里保存的不是一张大图片,而是十二张小图片.
客户的意思是这样

哎,真的要苦笑了,我都会开发frame.dll这样的啦,我也去QQ啦


zuguanqun啊,谢谢你哦,能不能交个朋友,我QQ3711382


其实你说的这个也很实现,不过需要一段时间,找个时间我用vc给你做个dll吧


真的啊,那太謝謝了


MARK


↑返回目录
前一篇: 请教一个Frame的问题!!!!!!!
后一篇: 求怎样判断checkbox里的复选框