• 解决了困扰一周的问题


    用了webupload,生成的是base64格式的

    <!DOCTYPE HTML>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title></title>
      <link media="all" rel="stylesheet" href="css/AlloyClip.css" type="text/css" />
      <style type="text/css">
    .clip, .clip2{
       500px; 
      height: 400px;
      margin: 10px;
      float: left;
    }
    h2{
      text-align: center;
    }
    .footer{
      clear: both;
      margin-top: 600px;
      text-align: center;
      font-size: 14px;
      color: #888;
      line-height: 22px;
    }
    .footer a{
      color: #888;
      text-decoration:none;
    }
      </style>
    </head>
    <body>
    <div class="clip"></div>
    图片:<img src="" alt="" id="img1"> 
    <!--<div class="clip2"></div>-->
    
    <script type="text/javascript" src="js/alloyimage.js"></script>
    <script type="text/javascript" src="js/alloyclip.min.js"></script>
    
    <script type="text/javascript">
      new $AC(".clip", 120, 120, 0).ok(function(base64, aiObj){
          console.log(typeof(base64));
          document.getElementById("img1").src=base64;
          //aiObj.saveFile("AlloyCliped.jpg", 0.8);
      });
    
    
    </script>
    
    
    </body>
    </html>
    

    然后项目是.net mvc获取这个并且存入数据库或者存入文件夹。

    1.sql数据库字段varchar(8000)都不够,字段改成二进制的

    2.上传有时候进不了后台,因为我的上传是ajax传的 data类型是"text"

     <script type="text/javascript">
      new $AC(".clip", 120, 120, 0).ok(function(base64, aiObj){
          //console.log(base64);
          document.getElementById("img1").src = base64;
          var bs4 = base64.substring(22);
          console.log(bs4);
          //aiObj.saveFile("AlloyCliped.jpg", 0.8);
          $("#ceshi").click(function () {
              $.ajax({
                  url: "/Clip/getbase",
                  
                  type: "POST",
                  async: false,
                  xhrFields: { withCredentials: true },
                  dataType: "text",
                  data:{imgbase:bs4},
                  success:function(data){
                      console("成功:"+data);
                  },
                  error:function(data){
                      console("失败:"+data);
                  }
              });
          });
      });
        </script>

    原因是 public ActionResult getbase(string imgbase)

    括号里面用对类型

    3.我还得继续做项目,直接看代码吧,嘿嘿

    public ActionResult getbase(string imgbase)
            {
                ClipBase64 cb = new ClipBase64();
                cb.imageID = 5;
                // byte[] base64  这个是byte的
                // string ceshibase 这个是string 的
                //cb.ceshibase = imgbase;
                Encoding.Default.GetBytes(imgbase);
                byte[] imgbyte = System.Convert.FromBase64String(imgbase);
                //MemoryStream ms = new MemoryStream(imgbyte, 0, imgbase.Length);
    
                //第一种可以这样
                //System.IO.File.WriteAllBytes(@"E:	est1.jpg", imgbyte);
                //第二种
                MemoryStream ms = new MemoryStream(imgbyte);
                FileStream fs = new FileStream(@"E:	est1.jpg", FileMode.Create);
                ms.WriteTo(fs);
                ms.Close();
                fs.Close();
    
    
                //int result = cm.clipImg(cb);
                //if (result > 0)
                //{
                //    ViewData["msg"] = "成功";
                //}
                //else
                //{
                //    ViewData["msg"] = "失败";
                //}
                return View();
            }


  • 相关阅读:
    js模版引擎Mustache介绍
    springMVC学习篇
    MyBatis参数传入集合之foreach动态sql
    eclipse注册码生成,在eclipse3.3.x上测试可用
    B
    jAVA笔记二
    J 分班(class)(NYIST 2019年校赛)
    H 幻方变换(puzzle)(NYIST 2019年校赛)
    E 旅游方案(travel)(南阳理工学院2019年校赛)
    ACM Computer Factory(网络流 POJ 3436,这可是我第一次写网络流)
  • 原文地址:https://www.cnblogs.com/MartinLee/p/7622726.html
Copyright © 2020-2023  润新知