0
我正在处理从数据库显示的此图像。我将字节数组从数据库转换为图像显示在我的图像标签上。从数据库中显示图像
这里是我上传的图片:
$("#uploadBtn").live("click", function() {
$("#uploading")
.ajaxStart(function() {
$(this).show();
})
.ajaxComplete(function() {
$(this).hide();
});
$.ajaxFileUpload
(
{
url: 'AjaxFileUploader.ashx?user=' + userId,
secureuri: false,
fileElementId: 'uploadControl',
dataType: 'json',
data: '{}',
success: function (mydata) {
alert("Image Successfully Uploaded");
$('#imgdefaultphoto').attr('src', 'ImageRetrieval.ashx?user=' + userId); //referencing the ImageRetrieval handler
hideUploadMask();
},
error: function() {
}
}
)
});
我有一个例外:
Argument exception Parameter is not valid. at the line with (*).
ImageRetrieval.ashx:
public void ProcessRequest(HttpContext context)
{
string userid = context.Request.QueryString["user"];
DBAccess dbacc = new DBAccess();
DataTable dt = dbacc.getImage(userid);
byte[] image = ((byte[])dt.Rows[0]["UserImage"]);
System.Drawing.Image img = byteArrayToImage(image);
MemoryStream stream = new MemoryStream();
img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();
stream.Position = 0;
byte[] data = new byte[stream.Length];
stream.Read(data, 0, (int)stream.Length);
stream.Dispose();
context.Response.Clear();
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(data);
}
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms); // exception line (*)
return returnImage;
}
任何想法?
您是否尝试过自定义触发选项选项? – TheVillageIdiot 2012-07-12 16:22:44
不,我不知道这一点。你有样品吗? – ljpv14 2012-07-12 16:23:16