<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    悟心

    成功不是將來才有的,而是從決定去做的那一刻起,持續累積而成。 上人生的旅途罷。前途很遠,也很暗。然而不要怕。不怕的人的面前才有路。

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      93 隨筆 :: 1 文章 :: 103 評論 :: 0 Trackbacks
    1.負責處理圖處的bean:
    //---------------------------------------------------------------
    package bean;

    import javax.imageio.ImageIO;
    import javax.imageio.IIOException;
    import java.awt.image.BufferedImage;
    import java.awt.Image;
    import java.io.File;
    import java.awt.image.AffineTransformOp;
    import java.awt.geom.AffineTransform;

    public class convertImage {


    private String fileInput ;
    private String fileOutput ;

    public convertImage()
    {

    }
    public String getFileInput() {
    return fileInput;
    }
    public 
    void setFileInput(String fileInput) {
    this.fileInput = fileInput;
    }
    public String getFileOutput() {
    return fileOutput;
    }
    public 
    void setFileOutput(String fileOutput) {
    this.fileOutput = fileOutput;
    }

    public 
    void convert()
    {
    try {
    File fi 
    = new File(fileInput); //大圖文件
    File fo = new File(fileOutput); //將要轉換出的小圖文件
    int nw = 150//定義寬為150
    int nh = 100//定義高為100
    AffineTransform transform = new AffineTransform();
    BufferedImage bis 
    = ImageIO.read(fi);
    int w = bis.getWidth();
    int h = bis.getHeight();

    double sx = (double)nw/w;
    double sy = (double)nh/h ;
    //判斷是橫向圖形還是堅向圖形
    if ( w > h ) //橫向圖形
    {
    if ( (int)(sx * h ) > nh ) //比較高不符合高度要求,就按高度比例
    {

     

    sx 
    = sy ;
    nw 
    = (int)(w*sx) ;
    }
    else
    {
    sy 
    = sx ;
    nh 
    = (int)( h*sy) ;
    }
    }
    else
    {
    if ( (int)(sy * w ) > nw ) 
    {
    sy 
    = sx ;
    nh 
    = (int)(h * sy ) ;
    }
    else
    {
    sx 
    = sy ;
    nw 
    = (int)(w*sx) ;
    }
    }

    transform.setToScale(sx,sy);
    AffineTransformOp ato 
    = new AffineTransformOp(transform,null);
    BufferedImage bid 
    = new BufferedImage(nw,nh,BufferedImage.TYPE_3BYTE_BGR);
    ato.filter(bis,bid);
    ImageIO.write(bid,
    "jpeg",fo);

    catch(Exception e) 
    {
    e.printStackTrace();
    }

    }

    2.上傳文件的upload.jsp
    --------------------------------------------------------------------
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>

    <title>My JSP 'upload.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">

    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    </head>

    <body>
    <html:form action="/upload.do" enctype="multipart/form-data">
    <html:file property="theFileone"/>
    <html:submit/>
    </html:form>

    </body>
    </html>
    //------------------------------------------------------------------------
    3.顯示成功頁面

    //------------------------------------------------------------------------
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ page contentType="text/html;charset=GB2312" %>
    <%
    String path 
    = request.getContextPath();
    String basePath 
    = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">

    <title>My JSP 'display.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">

    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    </head>

    <body>
    上傳成功. 
    <br>
    </body>
    </html>
    //---------------------------------------------------------------------
    4.Action 
    //Created by MyEclipse Struts
    //
     XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.1/xslt/JavaClass.xsl

    package com.mk.struts.action;

    import java.io.
    *;


    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.upload.FormFile;

    import com.mk.struts.form.UploadForm;

    import bean.convertImage;

    /*
    * MyEclipse Struts
    * Creation date: 03-28-2006

    * XDoclet definition:
    * @struts.action validate="true"
    */
    public class UploadAction extends Action {

    // --------------------------------------------------------- Instance Variables

    // --------------------------------------------------------- Methods

    /*
    * Method execute
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return ActionForward
    */
    public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) {

    // TODO Auto-generated method stub
    String encoding = request.getCharacterEncoding() ;
    if ( (encoding != null )&& (encoding.equalsIgnoreCase("uft-8")))
    {
    response.setContentType(
    "text/html;charset=gb2312") ; //如果沒有找定編碼,編碼格式設為gb2312 
    }

    UploadForm theForm 
    = (UploadForm) form ;
    FormFile fileone 
    = theForm.getTheFileone() ; //取得上傳的文件名

    try
    {
    //開始上傳文件
    String filePath = this.getServlet().getServletContext().getRealPath("/") ; //取得當前路徑
    InputStream stream = fileone.getInputStream() ; //把文件讀入
    ByteArrayOutputStream baos = new ByteArrayOutputStream() ;

    /*
    * 建立一個上傳文件的輸出流如果是linux系統請把"\\" 換成 "/"
    */
    OutputStream bos 
    = new FileOutputStream(filePath + fileone.getFileName()) ;

    request.setAttribute(
    "fileName",filePath + "/" + fileone.getFileName() ) ;
    int bytesRead = 0 ;
    byte[] buffer = new byte[8192] ;
    while( (bytesRead = stream.read(buffer,0,8192) ) != -1 )
    {
    bos.write(buffer,
    0,bytesRead) ;
    }

    bos.close();
    stream.close() ; 

    //上傳文件完成
    String oldurl= filePath + fileone.getFileName() ;
    String newurl
    = filePath + "min_" + fileone.getFileName() ; //新的縮略圖保存地址

    convertImage convert 
    = new convertImage() ;
    convert.setFileInput(oldurl) ;
    convert.setFileOutput(newurl) ;
    convert.convert() ;

    }

    catch(Exception e)
    {
    System.err.print(e) ;
    }
    return mapping.findForward("display");
    }

    }
    來源:http://www.ideagrace.com/html/doc/2006/04/21/00776.html
    posted on 2010-08-29 16:11 艾波 閱讀(425) 評論(0)  編輯  收藏 所屬分類: Application
    主站蜘蛛池模板: 亚洲精品国产精品乱码不卡| 日韩免费观看视频| 亚洲免费人成在线视频观看| 国产亚洲Av综合人人澡精品| 精品免费国产一区二区| 亚洲熟女www一区二区三区| 全免费a级毛片免费看不卡| 亚洲精品无码高潮喷水A片软| 美女被免费视频网站a国产| 亚洲精华国产精华精华液网站| 日韩精品视频免费网址| 美美女高清毛片视频黄的一免费| www.亚洲精品| 久久久久久国产a免费观看不卡| 亚洲色精品88色婷婷七月丁香 | 中文在线免费看视频| 亚洲成aⅴ人片在线观| 中文字幕在线观看亚洲视频| 久久精品国产亚洲AV未满十八| 在线永久免费观看黄网站| 黄页网址大全免费观看12网站| 亚洲JIZZJIZZ中国少妇中文| 一日本道a高清免费播放| 久久久久久久尹人综合网亚洲| 亚洲视频在线免费观看| 亚洲精品白色在线发布| 中文字幕无码不卡免费视频| 亚洲人成欧美中文字幕| 亚洲国产精品自在拍在线播放| 国产日韩一区二区三免费高清| 337p日本欧洲亚洲大胆艺术| 性感美女视频在线观看免费精品 | 国产精品视频永久免费播放| 亚洲AV无码精品国产成人| 亚洲乱码中文字幕手机在线| 无码国产精品一区二区免费3p| 亚洲人成人网毛片在线播放| 亚洲精品无码激情AV| 久久免费看黄a级毛片| 国产精品自拍亚洲| 亚洲嫩模在线观看|