在本地上传一个1M,尺寸为800*400的图片到远程计算机后,保留原图片一份,而且自动生成一份缩略图(尺寸便小,比如是200*100;文件字节也变小,比如,512K)。请问有这种技术可以实现我的要求吗?
    谢谢

解决方案 »

  1.   

    asp有个第三方控件这类的东西能解决,jsp好像也有个类什么的
      

  2.   

    <%@ page language="java" 
      import="java.io.*,java.awt.Image,java.awt.image.*,com.sun.image.codec.jpeg.*,java.sql.*,com.jspsmart.upload.*,java.util.*"
    %> <%!
    //  删除文件
    public void deleteFile(String filename)
    {
    java.io.File file = new java.io.File(filename);
    if(file.exists()) file.delete();
    } // 从指定的图像文件,创建新的所要求宽高的图像(以比例计算)
    public void createImage(String filename,String newname,int std_img_w, int std_img_h){
    java.io.File file = new java.io.File(filename); 
    try{
    Image oldimage = javax.imageio.ImageIO.read(file);  int old_w = oldimage.getWidth(null);
    int old_h = oldimage.getHeight(null); int new_w = old_w; 
    int new_h = old_h; if((old_w>std_img_w)||(old_h>std_img_h)){
    float tmpdouble  = std_img_w;
    float tagSize = old_w / tmpdouble; // 缩放比例

    tmpdouble = std_img_h;
    if(tagSize<(old_h/tmpdouble)) tagSize = old_h/tmpdouble;  new_w = Math.round(old_w/tagSize);
    new_h = Math.round(old_h/tagSize);
    } BufferedImage tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB); 
    tag.getGraphics().drawImage(oldimage,0,0,new_w,new_h,null); 
    oldimage.flush();

    FileOutputStream newfile = new FileOutputStream(newname); 
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newfile); 
    encoder.encode(tag); 
    tag.flush();
    newfile.close(); 
    }catch (Exception e){ 
    e.toString();
    }
    }
    %>
      

  3.   

    我也要用这个功能~关注一下~楼上的文件路径在那里写?filename吗?