欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

.net MVC+Bootstrap下使用localResizeIMG上傳圖片

 更新時(shí)間:2017年04月21日 11:40:45   作者:sj2016  
這篇文章主要為大家詳細(xì)介紹了.net MVC和Bootstrap下使用 localResizeIMG上傳圖片,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了使用localResizeIMG上傳圖片的具體代碼,供大家參考,具體內(nèi)容如下

需要加載的頭文件

 html:

<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/*”  這里有些手機(jī)可以拍照 有些不行 沒(méi)有具體測(cè)試統(tǒng)計(jì)

$("#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); //呈現(xiàn)圖像(拍照結(jié)果)
 $.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~")
 }
 });
 }
 });

界面樣式

后臺(tái)action  Base64StringToImage 需要把壓縮后的Base64轉(zhuǎn)換

[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/

參考文章:

localResizeIMG先壓縮后使用ajax無(wú)刷新上傳(移動(dòng)端)

移動(dòng)端使用localResizeIMG4壓縮圖片

基于javascript html5實(shí)現(xiàn)多文件上傳

JS實(shí)現(xiàn)異步上傳壓縮圖片

spring mvc+localResizeIMG實(shí)現(xiàn)HTML5端圖片壓縮上傳

HTML5+Canvas調(diào)用手機(jī)拍照功能實(shí)現(xiàn)圖片上傳(上)

HTML5實(shí)現(xiàn)微信拍攝上傳照片功能 遇到問(wèn)題的解決方法

js實(shí)現(xiàn)純前端的圖片預(yù)覽

推薦三款不錯(cuò)的圖片壓縮上傳插件(webuploader、localResizeIMG4、LUploader)

H5圖片壓縮與上傳實(shí)例

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論