请教上传头像的技术实现。 我想实现头像上传的功能,用户可以选择本地一张任意尺寸的相片,然后截图图片的固定大小作为用户的头像。有没有专门做这个功能的Jar。请做过这种功能的朋友指一条明路。谢谢。万分感激! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://download.csdn.net/source/2966573 你说的那种是用Flash实现的吧 这个可以完全用后台加前台JS处理。JS处理完后(只是处理的伪数据),发给后台处理的数据,后台对图片进行裁切,再返回到前台。 我不懂flash, 我搞java这方面的。 为方便大家,我改一下,可以直接点击进入了:http://download.csdn.net/source/2966573 http://download.csdn.net/source/1930839 首先在网页上是无法完全实现的。其他浏览器上ok,就是ie8有问题。问题有两个1.无法取得图片的真实路径,除非在客户端上设置,这个对于web应用来说是致命的2.有时无法显示预览图片,除非设置了信任站点综上,所有问题都是出现在前台。大致思路为:前台取得要切割的像素大小位置,上传到后台,由后台负责切割图片,生成新图 /** * 对图片进行处理 */public class ImageOperater { /** * 对图片进行缩放 * * @param srcFile 源文件 * @param dynameter 倍率 * @param x X坐标 * @param y Y坐标 * @param w 宽度 * @param h 长度 * @throws IOException */ public void zoomAndCutImage(File srcFile, String outputDir, double dynameter, int x, int y, int w, int h, String imageType) throws IOException { // 缩放处理开始 BufferedImage srcImage = ImageIO.read(srcFile); int srcWidth = (int) (srcImage.getWidth() * dynameter); int srcHeight = (int) (srcImage.getHeight() * dynameter); BufferedImage targetImage = new BufferedImage(srcWidth, srcHeight, BufferedImage.TYPE_INT_RGB); targetImage.getGraphics().drawImage(srcImage, 0, 0, srcWidth, srcHeight, null); // 剪切处理开始 CropImageFilter filter = new CropImageFilter(x, y ,w, h); Image tarImg = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(targetImage.getSource(), filter)); BufferedImage target = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); target.getGraphics().drawImage(tarImg, 0, 0, null); target.getGraphics().dispose(); File out = new File(outputDir); ImageIO.write(target, imageType, out); } public static void main(String args[]) throws Exception { File file = new File("D:\\r_xx2.jpg"); double dynameter = 0.940913426171621; int x = 63; int y = 129; int w = 120; int h = 120; new ImageOperater().zoomAndCutImage(file, "D:/test.jpg", dynameter, x, y, w, h, "JEPG"); System.out.println("End"); }}前台swing的话,lz自己搞定吧 一直不懂为什么CSDN的图片服务器挂这么久=.= jQuery可以,你可以找一下jQuery特效,看一下,很easy ** * 对图片进行处理 */public class ImageOperater { /** * 对图片进行缩放 * * @param srcFile 源文件 * @param dynameter 倍率 * @param x X坐标 * @param y Y坐标 * @param w 宽度 * @param h 长度 * @throws IOException */ public void zoomAndCutImage(File srcFile, String outputDir, double dynameter, int x, int y, int w, int h, String imageType) throws IOException { // 缩放处理开始 BufferedImage srcImage = ImageIO.read(srcFile); int srcWidth = (int) (srcImage.getWidth() * dynameter); int srcHeight = (int) (srcImage.getHeight() * dynameter); BufferedImage targetImage = new BufferedImage(srcWidth, srcHeight, BufferedImage.TYPE_INT_RGB); targetImage.getGraphics().drawImage(srcImage, 0, 0, srcWidth, srcHeight, null); // 剪切处理开始 CropImageFilter filter = new CropImageFilter(x, y ,w, h); Image tarImg = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(targetImage.getSource(), filter)); BufferedImage target = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); target.getGraphics().drawImage(tarImg, 0, 0, null); target.getGraphics().dispose(); File out = new File(outputDir); ImageIO.write(target, imageType, out); } public static void main(String args[]) throws Exception { File file = new File("D:\\r_xx2.jpg"); double dynameter = 0.940913426171621; int x = 63; int y = 129; int w = 120; int h = 120; new ImageOperater().zoomAndCutImage(file, "D:/test.jpg", dynameter, x, y, w, h, "JEPG"); System.out.println("End"); }} 嗯, 貌似用jquery 很容易 href传参数 hibernate中的一对多问题 如何让一条新闻在前台多个地方显示? dhtmlxconnection for java组件动态参数查询问题 java 程序中止问题 我做的程序gif下下来是乱码,望高手赐教! 有关取checkbox的值到action中去形成一个数组 关于SQLSERVER2000数据源的建立? oracal连接问题? 用jsp如何调用oracle带返回值的存储过程 求高手解答,calendar和Timestamp的转换,在线等待急急急 如何利用js控制单选按钮的选择的数量
JS处理完后(只是处理的伪数据),发给后台处理的数据,后台对图片进行裁切,再返回到前台。
为方便大家,我改一下,可以直接点击进入了:
http://download.csdn.net/source/2966573
问题有两个
1.无法取得图片的真实路径,除非在客户端上设置,这个对于web应用来说是致命的
2.有时无法显示预览图片,除非设置了信任站点综上,所有问题都是出现在前台。大致思路为:前台取得要切割的像素大小位置,上传到后台,由后台负责切割图片,生成新图
/**
* 对图片进行处理
*/
public class ImageOperater {
/**
* 对图片进行缩放
*
* @param srcFile 源文件
* @param dynameter 倍率
* @param x X坐标
* @param y Y坐标
* @param w 宽度
* @param h 长度
* @throws IOException
*/
public void zoomAndCutImage(File srcFile, String outputDir, double dynameter, int x, int y, int w, int h, String imageType) throws IOException {
// 缩放处理开始
BufferedImage srcImage = ImageIO.read(srcFile);
int srcWidth = (int) (srcImage.getWidth() * dynameter);
int srcHeight = (int) (srcImage.getHeight() * dynameter);
BufferedImage targetImage = new BufferedImage(srcWidth, srcHeight, BufferedImage.TYPE_INT_RGB);
targetImage.getGraphics().drawImage(srcImage, 0, 0, srcWidth, srcHeight, null);
// 剪切处理开始
CropImageFilter filter = new CropImageFilter(x, y ,w, h);
Image tarImg = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(targetImage.getSource(), filter));
BufferedImage target = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
target.getGraphics().drawImage(tarImg, 0, 0, null);
target.getGraphics().dispose();
File out = new File(outputDir);
ImageIO.write(target, imageType, out);
}
public static void main(String args[]) throws Exception {
File file = new File("D:\\r_xx2.jpg");
double dynameter = 0.940913426171621;
int x = 63;
int y = 129;
int w = 120;
int h = 120;
new ImageOperater().zoomAndCutImage(file, "D:/test.jpg", dynameter, x, y, w, h, "JEPG");
System.out.println("End");
}
}
前台swing的话,lz自己搞定吧
* 对图片进行处理
*/
public class ImageOperater {
/**
* 对图片进行缩放
*
* @param srcFile 源文件
* @param dynameter 倍率
* @param x X坐标
* @param y Y坐标
* @param w 宽度
* @param h 长度
* @throws IOException
*/
public void zoomAndCutImage(File srcFile, String outputDir, double dynameter, int x, int y, int w, int h, String imageType) throws IOException {
// 缩放处理开始
BufferedImage srcImage = ImageIO.read(srcFile);
int srcWidth = (int) (srcImage.getWidth() * dynameter);
int srcHeight = (int) (srcImage.getHeight() * dynameter);
BufferedImage targetImage = new BufferedImage(srcWidth, srcHeight, BufferedImage.TYPE_INT_RGB);
targetImage.getGraphics().drawImage(srcImage, 0, 0, srcWidth, srcHeight, null);
// 剪切处理开始
CropImageFilter filter = new CropImageFilter(x, y ,w, h);
Image tarImg = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(targetImage.getSource(), filter));
BufferedImage target = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
target.getGraphics().drawImage(tarImg, 0, 0, null);
target.getGraphics().dispose();
File out = new File(outputDir);
ImageIO.write(target, imageType, out);
}
public static void main(String args[]) throws Exception {
File file = new File("D:\\r_xx2.jpg");
double dynameter = 0.940913426171621;
int x = 63;
int y = 129;
int w = 120;
int h = 120;
new ImageOperater().zoomAndCutImage(file, "D:/test.jpg", dynameter, x, y, w, h, "JEPG");
System.out.println("End");
}
}