Html5+asp.net mvc 图片压缩上传
在做图片上传时,大图片如果没有压缩直接上传时间会非常长,因为有的图片太大,传到服务器上再压缩太慢了,而且损耗流量。
思路是将图片抽样显示在canvas上,然后用通过canvas.toDataURL方法得到base64字符串来实现压缩。
废话不多少不多说直接看代码:
本次测试使用了 zepto.min.js 插件,更新版本的下载请点击这里
主要js代码:
//图片压缩处理
; (function () {
/**
* 加载的时候进行抽样检测
* 在iOS中,大于2M的图片会抽样渲染
*/
function detectSubsampling(img) {
var iw = img.naturalWidth, ih = img.naturalHeight;
if (iw * ih > 1024 * 1024) { //大于百万像素的就会进行抽样
var canvas = document.createElement('canvas');
canvas.width = canvas.height = 1;
var ctx = canvas.getContext('2d');
ctx.drawImage(img, -iw + 1, 0);
// subsampled image becomes half smaller in rendering size.
// check alpha channel value to confirm image is covering edge pixel or not.
// if alpha value is 0 image is not covering, hence subsampled.
return ctx.getImageData(0, 0, 1, 1).data[3] === 0;
} else {
return false;
}
} /**
* Detecting vertical squash in loaded image.
* Fixes a bug which squash image vertically while drawing into canvas for some images.
*/
function detectVerticalSquash(img, iw, ih) {
var canvas = document.createElement('canvas');
canvas.width = 1;
canvas.height = ih;
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
var data = ctx.getImageData(0, 0, 1, ih).data;
// search image edge pixel position in case it is squashed vertically.
var sy = 0;
var ey = ih;
var py = ih;
while (py > sy) {
var alpha = data[(py - 1) * 4 + 3];
if (alpha === 0) {
ey = py;
} else {
sy = py;
}
py = (ey + sy) >> 1;
}
var ratio = (py / ih);
return (ratio === 0) ? 1 : ratio;
} /**
* Rendering image element (with resizing) and get its data URL
*/
function renderImageToDataURL(img, options, doSquash) {
var canvas = document.createElement('canvas');
renderImageToCanvas(img, canvas, options, doSquash);
return canvas.toDataURL("image/jpeg", options.quality || 0.8);
} /**
* Rendering image element (with resizing) into the canvas element
*/
function renderImageToCanvas(img, canvas, options, doSquash) {
var iw = img.naturalWidth, ih = img.naturalHeight;
if (!(iw + ih)) return;
var width = options.width, height = options.height;
var ctx = canvas.getContext('2d');
ctx.save();
transformCoordinate(canvas, ctx, width, height, options.orientation);
var subsampled = detectSubsampling(img);
if (subsampled) {
iw /= 2;
ih /= 2;
}
var d = 1024; // size of tiling canvas
var tmpCanvas = document.createElement('canvas');
tmpCanvas.width = tmpCanvas.height = d;
var tmpCtx = tmpCanvas.getContext('2d');
var vertSquashRatio = doSquash ? detectVerticalSquash(img, iw, ih) : 1;
var dw = Math.ceil(d * width / iw);
var dh = Math.ceil(d * height / ih / vertSquashRatio);
var sy = 0;
var dy = 0;
while (sy < ih) {
var sx = 0;
var dx = 0;
while (sx < iw) {
tmpCtx.clearRect(0, 0, d, d);
tmpCtx.drawImage(img, -sx, -sy);
ctx.drawImage(tmpCanvas, 0, 0, d, d, dx, dy, dw, dh);
sx += d;
dx += dw;
}
sy += d;
dy += dh;
}
ctx.restore();
tmpCanvas = tmpCtx = null;
} /**
* Transform canvas coordination according to specified frame size and orientation
* 根据帧的大小和方向调整canvas
* 方向值是来自EXIF标签
*/
function transformCoordinate(canvas, ctx, width, height, orientation) {
switch (orientation) {
case 5:
case 6:
case 7:
case 8:
canvas.width = height;
canvas.height = width;
break;
default:
canvas.width = width;
canvas.height = height;
}
switch (orientation) {
case 2:
// horizontal flip
ctx.translate(width, 0);
ctx.scale(-1, 1);
break;
case 3:
// 180 rotate left
ctx.translate(width, height);
ctx.rotate(Math.PI);
break;
case 4:
// vertical flip
ctx.translate(0, height);
ctx.scale(1, -1);
break;
case 5:
// vertical flip + 90 rotate right
ctx.rotate(0.5 * Math.PI);
ctx.scale(1, -1);
break;
case 6:
// 90 rotate right
ctx.rotate(0.5 * Math.PI);
ctx.translate(0, -height);
break;
case 7:
// horizontal flip + 90 rotate right
ctx.rotate(0.5 * Math.PI);
ctx.translate(width, -height);
ctx.scale(-1, 1);
break;
case 8:
// 90 rotate left
ctx.rotate(-0.5 * Math.PI);
ctx.translate(-width, 0);
break;
default:
break;
}
} var URL = window.URL && window.URL.createObjectURL ? window.URL :
window.webkitURL && window.webkitURL.createObjectURL ? window.webkitURL :
null; /**
* MegaPixImage class
*/
function MegaPixImage(srcImage) {
if (window.Blob && srcImage instanceof Blob) {
if (!URL) { throw Error("No createObjectURL function found to create blob url"); }
var img = new Image();
img.src = URL.createObjectURL(srcImage);
this.blob = srcImage;
srcImage = img;
}
if (!srcImage.naturalWidth && !srcImage.naturalHeight) {
var _this = this;
srcImage.onload = srcImage.onerror = function () {
var listeners = _this.imageLoadListeners;
if (listeners) {
_this.imageLoadListeners = null;
for (var i = 0, len = listeners.length; i < len; i++) {
listeners[i]();
}
}
};
this.imageLoadListeners = [];
}
this.srcImage = srcImage;
} /**
* Rendering megapix image into specified target element
*/
MegaPixImage.prototype.render = function (target, options, callback) {
if (this.imageLoadListeners) {
var _this = this;
this.imageLoadListeners.push(function () { _this.render(target, options, callback); });
return;
}
options = options || {};
var imgWidth = this.srcImage.naturalWidth, imgHeight = this.srcImage.naturalHeight,
width = options.width, height = options.height,
maxWidth = options.maxWidth, maxHeight = options.maxHeight,
doSquash = !this.blob || this.blob.type === 'image/jpeg';
if (width && !height) {
height = (imgHeight * width / imgWidth) << 0;
} else if (height && !width) {
width = (imgWidth * height / imgHeight) << 0;
} else {
width = imgWidth;
height = imgHeight;
}
if (maxWidth && width > maxWidth) {
width = maxWidth;
height = (imgHeight * width / imgWidth) << 0;
}
if (maxHeight && height > maxHeight) {
height = maxHeight;
width = (imgWidth * height / imgHeight) << 0;
}
var opt = { width: width, height: height };
for (var k in options) opt[k] = options[k];
target.tagName = target.tagName || "IMG";
var tagName = target.tagName.toLowerCase();
if (tagName === 'img') {
target.src = renderImageToDataURL(this.srcImage, opt, doSquash);
} else if (tagName === 'canvas') {
renderImageToCanvas(this.srcImage, target, opt, doSquash);
}
if (typeof this.onrender === 'function') {
this.onrender(target);
}
if (callback) {
callback();
}
if (this.blob) {
this.blob = null;
URL.revokeObjectURL(this.srcImage.src);
}
}; /**
* Export class to global
*/
if (typeof define === 'function' && define.amd) {
define([], function () { return MegaPixImage; }); // for AMD loader
} else if (typeof exports === 'object') {
module.exports = MegaPixImage; // for CommonJS
} else {
this.MegaPixImage = MegaPixImage;
} })(); ; (function ($) {
$.extend($, {
fileUpload: function (options) {
var para = {
multiple: true, //是否可以多选上传
filebutton: ".filePicker", //上传文件的按钮
uploadButton: null,
url: "/Home/NotCompressUploadImg", //小型图片不压缩上传url
filebase: "mfile", // 此参数要对应 mvc action 的 HttpPostedFileBase类型 参数名称 (和action的参数必须相同) base64strUrl: "/Home/CompressImgBase64Upload", //大图片压缩上传url
imgGreaterCompress: 1024, //图片的大小大于多少进行压缩上传 limitCount: 2, //(多选上传)一次最多选择上传的图片最大数量
maxUploadCount: 3, //最多能上传多少张图片 maxWidth: 300, //在客户端显示图片最大宽度
maxHeight: 300, //在客户端显示图片最大高度 previewImageClassName: "previewImg previewImg_1", //显示图片的样式类名称 inputFileImageClassName: "inputFileImage", auto: true, previewDivId : "preview", //图片预览,动态添加图片预览img标签,添加那个div内 previewZoom: true,
uploadComplete: function (jsonResultData) { //上传成功执行此函数 res是服务端返回的数据
var imgArray = document.getElementById(para.previewDivId).getElementsByTagName("img");
var finallyImg = document.getElementById(para.previewDivId).getElementsByTagName("img")[imgArray.length-1];
if (jsonResultData.Success) { //上传成功
finallyImg.setAttribute("serverFilePath",jsonResultData.FilePath); //给动态添加的标签添加 图片上传到服务器图片地址属性
console.log("uploadComplete", jsonResultData);
uploadCount++;
core.checkComplete();
} else { //上传未成功
alert("出错了!请重试");
finallyImg.remove(); //删除预览图片标签
} },
uploadError: function (err) { //上传失败执行此函数
console.log("uploadError", err);
},
onProgress: function (percent) { // 提供给外部获取单个文件的上传进度,供外部实现上传进度效果
console.log('进度条:'+percent);
},
};
para = $.extend(para, options); var $self = $(para.filebutton);
//先加入一个file元素(上传文件按钮)
var multiple = ""; // 设置多选的参数
para.multiple ? multiple = "multiple" : multiple = "";
$self.css('position', 'relative');
$self.append('<input id="fileImage" class='+para.inputFileImageClassName+' style="opacity:0;position:absolute;top: 0;left: 0;width:100%;height:100%" accept="image/*" type="file" size="30" name="fileselect[]" ' + multiple + '>'); var doms = {
"fileToUpload": $self.find("#fileImage"),
"thumb": $self.find(".thumb"),
"progress": $self.find(".upload-progress") //进度条
}; function getBase64Image(img) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height; var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height); var dataURL = canvas.toDataURL("image/jpeg");
return dataURL; // return dataURL.replace("data:image/png;base64,", "");
}
function simpleSize(size) {
if (!size) return "0";
if (size < 1024) {
return size;
}
var kb = size / 1024;
if (kb < 1024) {
return kb.toFixed(2) + "K";
}
var mb = kb / 1024;
if (mb < 1024) {
return mb.toFixed(2) + "M"; }
var gb = mb / 1024;
return gb.toFixed(2) + "G";
};
//Convert DataURL to Blob to send over Ajax
function dataURItoBlob(dataUrl) {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
var byteString = atob(dataUrl.split(',')[1]); // separate out the mime component
var mimeString = dataUrl.split(',')[0].split(':')[1].split(';')[0]; // write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ab], { type: 'image/jpeg' });
} var uploadCount = 0;
var core = {
fileSelected: function () {
var files = $("#fileImage")[0].files;
var count = files.length;
if (count +document.getElementById(para.previewDivId).getElementsByTagName("img").length> para.maxUploadCount) { //最大只能上传多少张图片(document.getElementById(para.previewDivId).getElementsByTagName("img").length 获取已经上传了多少张图片)
alert("最多只能上传"+para.maxUploadCount+"张图片!");
return;
}
console.log("共有" + count + "个文件");
for (var i = 0; i < count; i++) {
if (i >= para.limitCount) { //最大一次性选择多少张图片
alert("最多只能选择"+para.limitCount+"张图片!");
break;
} var item = files[i];
console.log("原图片大小", item.size); if (item.size > para.imgGreaterCompress) { //图片打印多少M进行压缩上传
console.log("图片大于2M,开始进行压缩..."); (function(img) {
var mpImg = new MegaPixImage(img);
var resImg = document.getElementById("resultImage");
resImg.file = img;
mpImg.render(resImg, { maxWidth: para.maxWidth, maxHeight: para.maxHeight, quality: 1 }, function() {
var base64 = getBase64Image(resImg);
var base641 = resImg.src;
console.log("base64", base64.length, simpleSize(base64.length), base641.length, simpleSize(base641.length));
if (para.auto) core.uploadBase64str(base64);
});
})(item); } else {
if (para.auto) core.uploadFile(item);
}
core.previewImage(item);
}
},
uploadBase64str: function (base64Str) {
var formdata = new FormData();
formdata.append("base64str", base64Str);
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", function (e) {
var percentComplete = Math.round(e.loaded * 100 / e.total);
para.onProgress(percentComplete.toString() + '%');
});
xhr.addEventListener("load", function (e) {
var jsonResultData= JSON.parse(xhr.responseText);
para.uploadComplete(jsonResultData);
});
xhr.addEventListener("error", function (e) {
para.uploadError(e);
}); xhr.open("post", para.base64strUrl, true);
xhr.send(formdata);
},
uploadFile: function (file) {
// console.log("开始上传");
var formdata = new FormData(); formdata.append(para.filebase, file);//这个名字要和mvc后台配合 var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", function (e) { var percentComplete = Math.round(e.loaded * 100 / e.total);
para.onProgress(percentComplete.toString() + '%');
});
xhr.addEventListener("load", function (e) {
var jsonResultData= JSON.parse(xhr.responseText);
para.uploadComplete(jsonResultData);
});
xhr.addEventListener("error", function (e) {
para.uploadError(e);
}); xhr.open("post", para.url, true);
xhr.send(formdata);
},
checkComplete:function() {
var all = (doms.fileToUpload)[0].files.length;
if (all == uploadCount) {
console.log(all + "个文件上传完毕");
doms.fileToUpload.remove(); //删除上次动态添加 上传按钮
//input有一个问题就是选择重复的文件不会触发change事件,所以做了一个处理,再每次上传完之后删掉这个元素再新增一个input。
$self.append('<input id="fileImage" class='+para.inputFileImageClassName+' style="opacity:0;position:absolute;top: 0;left: 0;width:100%;height:100%" accept="image/*" type="file" size="30" name="fileselect[]" ' + multiple + '>'); }
},
uploadFiles: function () {
var files = (doms.fileToUpload)[0].files;
for (var i = 0; i < files.length; i++) {
core.uploadFile(files[i]);
}
},
previewImage: function (file) { //将压缩后的图片显示
if (!para.previewZoom) return;
var img = document.createElement("img");
img.file = file;
img.className =para.previewImageClassName; //样式类名称 (添加一个)
//img.className = "previewImg previewImg_1"; //样式类名称(添加两个)
//img.classList.add("previewImg"); //添加样式类
//img.classList.add("previewImg_1"); //添加样式类
//img.setAttribute("test","aaa");
$(para.previewZoom).append(img);
// 使用FileReader方法显示图片内容
var reader = new FileReader();
reader.onload = (function (aImg) {
return function (e) {
aImg.src = e.target.result;
};
})(img);
reader.readAsDataURL(file);
}
}
$(document).on("change", "#fileImage", function () {
core.fileSelected();
}); $(document).on("click", para.filebutton, function () {
console.log("clicked");
});
if (para.uploadButton) {
$(document).on("click", para.uploadButton, function () {
core.uploadFiles();
});
}
}
});
})(Zepto);
视图页面代码:
@{
ViewBag.Title = "h5图片压缩与上传";
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<style>
.filePicker
{
background: none repeat scroll 0 0 #00B7EE;
border-radius: 3px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
color: #FFFFFF;
cursor: pointer;
display: inline-block;
font-size: 18px;
height: 44px;
line-height: 44px;
width: 90%;
min-width: 120px;
margin: 0 auto 0px;
overflow: hidden;
transition: background 0.2s;
-moz-transition: background 0.2s;
-webkit-transition: background 0.2s;
-o-transition: background 0.2s;
}
#preview
{
margin-top: 30px;
}
#preview img
{
max-width: 30%;
} .previewImg {
border:5px solid red;
} .previewImg_1 {
min-width: 120px;
} .inputFileImage {
border:5px solid red;
}
</style>
<body>
<div class="page" id="upload">
<h2>
测试H5图片压缩与上传</h2>
<div id="dd" class="filePicker">
点击选择文件</div>
<img id="resultImage" style="display: none;"/>
<div id="preview">
</div>
</div>
<button onclick="GetServerFilePath('preview')">获取上传到服务端图片路径</button>
<script src="/Scripts/zepto.min.js" type="text/javascript"></script>
<script src="/Scripts/h5upload.js" type="text/javascript"></script>
<script>
var para = { filebutton: "#dd", previewZoom: "#preview", previewDivId: "preview" };
$.fileUpload(para); function GetServerFilePath(previewDivId) {
var serverFilePathArray = []; //存储服务端返回图片路径
var imgArray = document.getElementById(previewDivId).getElementsByTagName("img");
for (var i = 0; i < imgArray.length; i++) {
serverFilePathArray.push(imgArray[i].getAttribute("serverFilePath"));
}
alert(serverFilePathArray.join(","));
return serverFilePathArray;
} </script>
</body>
</html>
控制器代码:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc; namespace H5UploadDemo.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/ public ActionResult Index()
{
return View();
} /// <summary>
/// 未压缩上传
/// </summary>
/// <param name="mfile"></param>
/// <returns></returns>
[HttpPost]
public ActionResult NotCompressUploadImg(HttpPostedFileBase mfile)
{
if (mfile != null)
{
var path = "/Upload/Image/";
var uploadpath = Server.MapPath("~"+path);
if (!Directory.Exists(uploadpath))
{
Directory.CreateDirectory(uploadpath);
}
string fileName = Path.GetFileName(mfile.FileName);// 原始文件名称
string fileExtension = Path.GetExtension(fileName); // 文件扩展名
string saveName = Guid.NewGuid() + fileExtension; // 保存文件名称 这是个好方法。
//string saveName = Encrypt.GenerateOrderNumber() + fileExtension; // 保存文件名称 这是个好方法。
mfile.SaveAs(uploadpath + saveName); return Json(new { Success = true, FilePath = path + saveName, Message = "上传成功!" });
}
return Json(new { Success = false, Message = "请选择要上传的文件!" }, JsonRequestBehavior.AllowGet);
} /// <summary>
/// 压缩上传
/// </summary>
/// <param name="base64str"></param>
/// <returns></returns>
[HttpPost]
public ActionResult CompressImgBase64Upload(string base64str)
{
try
{
var imgData = base64str.Split(',')[];
//过滤特殊字符即可
string dummyData = imgData.Trim().Replace("%", "").Replace(",", "").Replace(" ", "+");
if (dummyData.Length % > )
{
dummyData = dummyData.PadRight(dummyData.Length + - dummyData.Length % , '=');
}
byte[] byteArray = Convert.FromBase64String(dummyData);
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArray))
{
var img = System.Drawing.Image.FromStream(ms);
var path = "/Upload/Image/";
var uploadpath = Server.MapPath("~" + path);
if (!Directory.Exists(uploadpath))
{
Directory.CreateDirectory(uploadpath);
}
var saveName = Guid.NewGuid() + ".jpg";
img.Save(uploadpath+saveName);
return Json(new { Success = true, FilePath = path + saveName, Message = "上传成功!" });
}
}
catch (Exception e)
{
return Json(new { Success = false, FilePath ="", Message = "出错了!" }); }
} }
}
完整代码地址:http://pan.baidu.com/s/1c2LuVDm 密码:gwdc
Html5+asp.net mvc 图片压缩上传的更多相关文章
- ASP.NET MVC图片管理(上传,预览与显示)
先看看效果(下面gif动画制作有点大,5.71MB): 题外话:上面选择图片来源于Insus.NET的新浪微博:http://weibo.com/104325017 也是昨晚(2015-07-03)I ...
- MVC图片上传、浏览、删除 ASP.NET MVC之文件上传【一】(八) ASP.NET MVC 图片上传到服务器
MVC图片上传.浏览.删除 1.存储配置信息 在web.config中,添加配置信息节点 <appSettings> <add key="UploadPath" ...
- 基于vue + axios + lrz.js 微信端图片压缩上传
业务场景 微信端项目是基于Vux + Axios构建的,关于图片上传的业务场景有以下几点需求: 1.单张图片上传(如个人头像,实名认证等业务) 2.多张图片上传(如某类工单记录) 3.上传图片时期望能 ...
- Asp.net mvc 大文件上传 断点续传
Asp.net mvc 大文件上传 断点续传 进度条 概述 项目中需要一个上传200M-500M的文件大小的功能,需要断点续传.上传性能稳定.突破asp.net上传限制.一开始看到51CTO上的这 ...
- ASP.NET MVC+LayUI视频上传
前言: 前段时间在使用APS.NET MVC+LayUI做视频上传功能的时,发现当上传一些内存比较大的视频就会提示上传失败,后来通过查阅相关资料发现.NET MVC框架为考虑安全问题,在运行时对请求的 ...
- asp.net实现图片在线上传并在线裁剪
1.说明 接上一篇文章uploadify实现多附件上传完成后,又突然用到头像上传并在线裁剪.在网上找个众多例子都没有符合要求的,有一篇文章写的不错,就是文旺老兄写的这篇Asp.Net平台下的图片在线裁 ...
- 三款不错的图片压缩上传插件(webuploader+localResizeIMG4+LUploader)
涉及到网页图片的交互,少不了图片的压缩上传,相关的插件有很多,相信大家都有用过,这里我就推荐三款,至于好处就仁者见仁喽: 1.名气最高的WebUploader,由Baidu FEX 团队开发,以H5为 ...
- 纯原生js移动端图片压缩上传插件
前段时间,同事又来咨询一个问题了,说手机端动不动拍照就好几M高清大图,上传服务器太慢,问问我有没有可以压缩图片并上传的js插件,当然手头上没有,别慌,我去网上搜一搜. 结果呢,呵呵...诶~又全是基于 ...
- springMVC多图片压缩上传的实现
首先需要在配置文件中添加配置: <!--配置文件的视图解析器,用于文件上传,其中ID是固定的:multipartResolver--> <bean id="multipar ...
随机推荐
- python+eclipse环境搭建
一.Eclipse 的安装 Eclipse的安装是很容易的.Eclipse是基于java的一个应用程序,因此需要一个java的运行环境(JRE)才行.(我这里主要介绍windows下的安装) JRE的 ...
- 安卓奇葩问题之SQLite条件查找不到数据
今天真是日了狗了. 先说需求:要做一个累死支付宝首页的可自定义的栏目.栏目是动态从后台获取的,所以就会有一个本地数据和后台数据的同步问题.为了方便对本地数据的增删改查,首先想到SQLite. 然后就写 ...
- CodeForces 743B Chloe and the sequence (递归)
题意:给定n和k,求第n个序列中第k个数是多少,序列是这样构造,原来只有1,然后再copy一遍放在到后面再在中间放上一个没有出现过的最小整数,就变成了 121,下次就成了1213121. 析:很明显是 ...
- 在Windows7 下调试CodeSmith 注意事项
编写CodeSmith模板和编写程序一样,也需要进行调试,CodeSmith支持使用CLR’s Just-in-Time debugger调试模板. 要调试模板,首先要在CodeTemplate声明中 ...
- 我的Sharepoint母版页的使用
在Sharepoint 2010母版页文件夹里面,有一个叫v4.master的母版页文件. 在它的基础上修改成想要的母版页.我们用最少的修改完成我们想要的效果. 我们有时是要这样的一个母版页,顶部Ri ...
- ruby使用DBI连接MySQL数据库发生异常:in `error': Can't connect to MySQL server on 'localhost' (10061) (DBI::DatabaseError)
Ruby使用DBI连接MySQL数据库一般为: require "dbi" dbh = DBI.connect("dbi:Mysql:test:localhost&quo ...
- onBlur事件与onfocus事件(js)
onFocus事件就是当光标落在文本框中时发生的事件. onBlur事件是光标失去焦点时发生的事件. 可以编如下例子 1.html <HTML><HEAD><TITL ...
- 用MOS管防止电源反接的原理
电源反接,会给电路造成损坏,不过,电源反接是不可避免的.所以,我么就需要给电路中加入保护电路,达到即使接反电源,也不会损坏的目的. 一般可以使用在电源的正极串入一个二极管解决,不过,由于二极管有压降, ...
- STM32的DMA
什么是DMA?其全称是:Direct Memory Access:根据ST公司提供的相关信息,DMA是STM32中一个独立与Cortex-M3内核的模块,有点类似与ADC.PWM.TIMER等模块:主 ...
- libmegjb.so加载问题调试和分析
欢迎转载opendevkit文章, 文章原始地址: http://www.opendevkit.com/?e=70 01-01 00:09:21.084: D/dalvikvm(10394): Try ...