当前位置: 首页 > 编程语言 > C#

使用通用处理程序的动态图像(来自数据库)Share

时间:2023-04-11 11:24:29 C#

使用通用处理程序的动态图像(来自数据库)但它就是行不通。我试过下面的代码,但我似乎无法让它工作。任何人都可以发现我做错了什么,或者有一些建议吗?使用System.Web;使用System.Linq;使用System.Data.Entity;公共类IconsDb:IHttpHandler{publicvoidProcessRequest(HttpContextcontext){context.Response.ContentType="text/plain";context.Response.Write("你好世界");Int32图标标识;如果(context.Request.QueryString["id"]!=null)iconId=Convert.ToInt32(context.Request.QueryString["id"]);elsethrownewArgumentException("没有指定参数");context.Response.ContentType="图片/gif";//System.IO.Streamstrm=ShowEmpImage(iconId);vardb=newUdINaturen.UdINaturenContext();varGetIcon=(fromiindb.subcategoryiconswherei.id==iconIdselecti.picture).FirstOrDefault();对象img=GetIcon;System.IO.MemoryStreammemStream=newSystem.IO.MemoryStream((byte[])Convert.FromBase64String(GetIcon));System.Drawing.BitmapbitImage=newSystem.Drawing.Bitmap((System.Drawing.Bitmap)System.Drawing.Image.FromStream(memStream));字节[]buffer=memStream.ToArray();context.Response.ContentType="图片/gif";//context.Response.OutputStream.Write(buffer,0,buffer.Length);//上下文.Response.WriteFile();context.Response.BinaryWrite(缓冲区);//上下文.Response.Flush();}publicboolIsReusable{get{returntrue;}}}哇,好的不知道旧代码有多少,应该注释掉或w/e但尝试这样的事情:以上是C#学习教程:使用通用处理程序的动态图像(来自数据库)的全部内容,如果有用的话给大家和需要了解更多C#学习教程的,希望大家多多关注——publicvoidProcessRequest(HttpContextcontext){inticonId;if(string.IsNullOrEmpty(context.Request.QueryString["id"])||!int.TryParse(context.Request.QueryString["id"],outiconId))thrownewArgumentException("没有指定参数");context.Response.ContentType="图片/gif";vardb=newUdINaturen.UdINaturenContext();varGetIcon=(fromiindb.subcategoryiconswherei.id==iconIdselecti.picture).FirstOrDefault();byte[]buffer=(byte[])Convert.FromBase64String(GetIcon);context.Response.ContentType="图片/gif";context.Response.BinaryWrite(缓冲区);context.Response.Flush();}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: