首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

tif格式的base64码图片数据展示到页面

2012-09-03 
tif格式的base64码图片数据显示到页面%@ page contentTypetext/html charsetGBK %%@ page import

tif格式的base64码图片数据显示到页面
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.io.InputStream"%>
<%@ page import="java.io.IOException"%>
<%@ page import="javax.servlet.ServletOutputStream"%>
<%@ page import="java.sql.*"%>
<%@ page import="ench.base.database.DBManager"%>
<%@ page import="java.sql.Blob"%>
<%@ page import="sun.misc.BASE64Decoder"%>
<%@ page import="java.io.OutputStream"%>
<%@ page import="java.io.FileOutputStream"%>
<%
  String ipaddress = (String) request.getParameter("ipaddress");
  String invoiceindex=(String) request.getParameter("invoiceindex");
  String sql = "select t.imagecode from tax_invoice t where t.invoiceindex='"+invoiceindex+"'";
  Connection con = null;
  Statement stmt = null;
  ResultSet rs = null;
  java.sql.Blob blob = null;
  String imgFilePath = "";
  String imgFileUrl = "";
  try {
    con = DBManager.getConnection();
    con.setAutoCommit(false);
    stmt = con.createStatement();
    rs = stmt.executeQuery(sql);
    if (rs.next()) {
      blob = (Blob) rs.getBlob("imagecode");
      if (blob != null ) {
        String blobString  = new String(blob.getBytes(1, (int) blob.length()));
       
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] blobbytes = decoder.decodeBuffer(blobString);
        System.out.println(blobbytes.length);
        for(int i=0;i<blobbytes.length;++i)
        {
          if(blobbytes[i]<0)
          {//调整异常数据
            blobbytes[i]+=256;
          }
        }
       
        //生成tif图片
        //本地测试
        //        imgFilePath = "E:/project/klgas_j2ee/02受控空间/src/code/KunLun_web/kunlun/temp/tmp"+invoiceindex+".tif";//新生成的图片
        //        imgFileUrl = "http://localhost:8080/kunlun/temp/tmp"+invoiceindex+".tif";
        //服务器发布
        imgFilePath = "/bea/user_projects/domains/web/kunlun/tmp/tmp"+invoiceindex+".tif";//新生成的图片
        imgFileUrl = "http://"+ipaddress+"/kunlun/tmp/tmp"+invoiceindex+".tif";
        OutputStream os = new FileOutputStream(imgFilePath);
        os.write(blobbytes);
        os.flush();
        os.close();
       
       
      }
    }
   
    con.setAutoCommit(true);
   
    DBManager.close(rs,stmt,con);
  }
  catch(IOException e)
  {
    e.printStackTrace();
    throw new Exception(e);
  }
  catch (Exception ex) {
    ex.printStackTrace();
    throw ex;
  }
%>

<script type="text/javascript">
  function setImage(){
    var bFlag = document.form1.ImageEx.AutoFit;
    document.form1.ImageEx.BkColorR = 128;
    document.form1.ImageEx.BkColorG = 128;
    document.form1.ImageEx.BkColorB = 128;
    document.form1.ImageEx.AutoFit = !bFlag;
    //document.form1.ImageEx.SetImageFile("<%=imgFilePath%>");
    document.form1.ImageEx.URL = ("<%=imgFileUrl%>");
  }
 
  function setURL(){
    var urlPath = document.form1.urlPath.value;
    if (urlPath.Length == 0){
      alert();
      return;
    }
    document.form1.ImageEx.URL = urlPath;
  }
  function setBackground(){
    document.form1.ImageEx.BkColorR = 128;
    document.form1.ImageEx.BkColorG = 128;
    document.form1.ImageEx.BkColorB = 128;
  }
  function AutoFit(){
    var bFlag = document.form1.ImageEx.AutoFit;
    document.form1.ImageEx.AutoFit = !bFlag;
  }
</script>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
</head>
<body onload="setImage()">
  <form name="form1">
    <div align="center">
      <table border="0" width="100%" height="100%">
        <tr width="100%">
          <td height="100%">
            <object classid="clsid:FB4CFDA6-C949-4911-9ABA-D41E2CAE78E7" name="ImageEx" width="100%" height="100%">
            </object>
          </td>
        </tr>
      </table>
    </div>
  </form>
</body>

</html>

热点排行