在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Since the images are stored in a database (BLOB), we need to retrieve the image as a byte array and do a binary write for the images to display in the webpage. HTTPHandler Synchronous HttpHandler Asynchronos HttpHandler Synchronous HttpHandler should implement System.Web.IHttpHandler 同步的, IHttpHandler成员有两个 具体步骤:
string imageid = context.Request.QueryString["ImID"];
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString); connection.Open(); SqlCommand command = new SqlCommand("select Image from ImageTable where ImageID="+imageid, connection); SqlDataReader dr = command.ExecuteReader(); dr.Read(); context.Response.BinaryWrite((Byte[])dr[0]); connection.Close(); context.Response.End(); ProcessRequest方法是如何get the access of Response object? 看ProcessRequest方法签名
].ConnectionString);
2. GridViewconnection.Open(); SqlCommand command = new SqlCommand("select Image from GamePictures where ImageID=" + imageid, connection); SqlDataReader dr = command.ExecuteReader(); dr.Read(); Stream str = new MemoryStream((Byte[])dr[0]); Bitmap initialBMP = new Bitmap(str); //With the help of Graphics class, the thumbnail image is constructed from the original bitmap Bitmap thumbnailImage = new Bitmap(100, 100); Graphics g = Graphics.FromImage(thumbnailImage); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.FillRectangle(Brushes.White, 0, 0, 100, 100); g.DrawImage(initialBMP, 0, 0, 100, 100); //make thumbnail image to byte array MemoryStream ms = new MemoryStream(); thumbnailImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] bmpBytes = ms.GetBuffer(); thumbnailImage.Dispose(); ms.Close(); //BinaryWrite context.Response.BinaryWrite(bmpBytes); connection.Close(); context.Response.End();
<asp:TemplateField HeaderText="Thumbnail(can click)">
<ItemTemplate> <a href="javascript:void(window.open('<%# "FullImageHandler.ashx?ImID="+ Eval("ImageID")%>','_blank','toolbar=no,menubar=no'))" > <asp:Image ID="Image1" runat="server" ImageUrl='<%# "ThumbnailHandler.ashx?ImID="+ Eval("ImageID") %>'/> </a> </ItemTemplate> </asp:TemplateField> 图片是经过ThumbnailHandler.ashx处理了,点击图片,调用JavaScript window.open |
请发表评论