zoukankan      html  css  js  c++  java
  • .net MVC + Bootstrap 下使用 localResizeIMG上传图片

    需要加载的头文件

    <div class="form-group">
                <label class="col-sm-6 control-label" for="inputfile">维修照片上传</label>
                <div class="col-sm-6 ">
                    <div style="background:url(../../fonts/add.png) no-repeat;151px;height:150px;float:left;" id="div1">
                        <input type="file" accept="image/*" id="file" class="selectinput" style="151px;height:150px;opacity:.01">
                    </div>
    
                </div>
            </div>

    accept=“image/*” 这里有些手机可以拍照 有些不行 没有具体测试统计
    $("#file").localResizeIMG({
             400,
            //height: 200,
            quality: 1,
            success: function (result) {
                var img = new Image();
                img.src = result.base64;
    
                //$("body").append(img);
                $("#odd").append(img); //呈现图像(拍照結果)
                $.ajax({
                    url: "/Home/UploadImg",
                    type: "POST",
                    data: { "formFile": result.clearBase64, "RepairNum": $('#RepairNum').val()},
                    dataType: "HTML",
                    timeout: 1000,
                    error: function () {
                        alert("ajax Error");
                    },
                    success: function (data) {
                        //alert("Uploads success~")
                    }
                });
            }
        });

    界面样式

    后台action  Base64StringToImage 需要把压缩后的Base64转换

    [HttpPost]
            public ActionResult UploadImg()
            {
                var file = Request["formFile"];
                var id = Request["RepairNum"];
    
                string fileName = "1.jpeg";
                string filePath = Server.MapPath("~/Upload/" + fileName);
    
                try
                {
                    Base64StringToImage(file, filePath);
                    //upImg.SaveAs(filePhysicalPath);
                    //Session["ImgPath"] = path;
                    //Base64StringToImage(file,);
                    return Content("上传成功");
                }
                catch
                {
                    return Content("上传异常 !");
    
                }
            }
    
            protected void Base64StringToImage(string strbase64, string filepath)
            {
                try
                {
                    byte[] arr = Convert.FromBase64String(strbase64);
                    MemoryStream ms = new MemoryStream(arr);
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
                    //bmp.Dispose();  
                    bmp.Save(filepath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    ms.Close();
                }
                catch (Exception ex)
                {
                }
            }

    参考和下载GitHub

    https://github.com/lyg945/localResizeIMG/tree/master/

    参考博客:

    http://www.cnblogs.com/manongxiaobing/p/4720568.html

    http://www.cnblogs.com/52fhy/p/5355601.html

    http://www.cnblogs.com/weapon-x/p/5237064.html

    https://my.oschina.net/zerodeng/blog/526355?p={{totalPage}}

    http://blog.csdn.net/mr_smile2014/article/details/51701674

    http://blog.csdn.net/hu1991die/article/details/40585581

    https://my.oschina.net/hzplay/blog/160806?p=1&temp=1492528670025#blog-comments-list

    http://www.cnblogs.com/fsjohnhuang/p/3925827.html

    http://www.cnblogs.com/brandonhulala/p/6080349.html

    http://www.cnblogs.com/stoneniqiu/p/5957356.html

  • 相关阅读:
    第六阶段·数据库MySQL及NoSQL实践第1章·章节一MySQL数据库
    小象和老鼠
    好句子啊
    LGTB 与 序列
    最小环
    精灵魔法
    C#委托之我见
    MySQL——优化ORDER BY语句
    MySQL——索引实现原理
    是什么影响了数据库索引选型?
  • 原文地址:https://www.cnblogs.com/seanjack/p/6742767.html
Copyright © 2011-2022 走看看