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