.net MVC + Bootstrap 下行使 localResizeIMG上污染图片

待加载的头文件

图片 1

 

<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;width:151px;height:150px;float:left;" id="div1">
                    <input type="file" accept="image/*" id="file" class="selectinput" style="width:151px;height:150px;opacity:.01">
                </div>

            </div>
        </div>

accept=“image/*”  这里有些手机可以拍照 有些不行 没有具体测试统计

$("#file").localResizeIMG({
        width: 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~")
                }
            });
        }
    });

界面样式

图片 2

后台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

 

相关文章