我从文件系统中拉出一个简单的JPG像这样...
var objz = "C:\\projects\\Desert.jpg";
byte[] imageSampleData = ReadImageToBytes(objz);
return imageSampleData;(阅读img到btyes的实现如下)
byte[] ReadImageToBytes(string sPath)
{
byte[] data = null;
FileInfo fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;
FileStream fStream = new FileStream(sPath, FileMode.Open,
FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);
data = br.ReadBytes((int)numBytes);
return data;
}然后,我试图从ASPNET MVC ActionResult返回这样的...
return File(byteArrayFromMethodAbove, "image/jpg");然后在客户端上,我试图设置一个图像的src像这样...
$(document).ready(function () {
loadImage();
});
function loadImage() {
$.ajax({
type: "GET",
url: "http://localhost:49415/Home/About",
data: {},
dataType: "jpg",
success: function (datasrc) {
$('#fk').attr('src', datasrc);
}
});
}
但到目前为止,该图像似乎并不符合我在做客户端(或编码是完全错误的)。目前看着萤火虫,我确实看到一些疯狂的数据作为src,但它看起来并不正确。
我在网站上找到了ton / question /回答,但其中没有一个似乎真正起作用
任何帮助将非常感谢(使用MVC 2和jQuery 1.4.1)