我將我的圖像存儲在sqlserver數據庫中。在我的數據庫中,我有字段Id,Name,Image。 我嘗試保存圖像:如何在js中顯示圖像?
Image imag = Image.FromFile(filePath);
byte[] imageData;
using (MemoryStream ms = new MemoryStream())
{
imag.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
imageData = ms.ToArray();
}
var dc = new ImagesDataContext();
dc.Images.InsertOnSubmit(new Image() { Id = 125, Image1 = imageData, Name = "testIm" });
在我一般的處理程序我ruturn JSON objec與圖片收集:
JavaScriptSerializer serializer = new JavaScriptSerializer();
context.Response.ContentType = "application/json";
List<Image> listOfImages = DatabaseAccessor.GetImages();
context.Response.Write(serializer.Serialize(listOfImages));
如何顯示使用javascript我的網頁上的圖片?