qq_766202417 2015-04-02 09:12 采纳率: 22.2%
浏览 3233
已采纳

asp.net 一般处理程序获取图片

asp.net 利用一般处理程序 怎么获取数据库中的图片(二进制数据)

一般处理程序
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.IO;
using DingDan;
using WEIP.Common;

namespace DingDan.OA.Staff.Center
{
///
/// StffIcon 的摘要说明
///
public class StffIcon : IHttpHandler
{

    //员工信息
    ProductStaffBasic Psb = new ProductStaffBasic();
    //员工信息实体
    ProductStaffBasicEntity PsbE = new ProductStaffBasicEntity();

    public void ProcessRequest(HttpContext context)
    {
        MemoryStream ms = null;
        try
        {
            context.Response.ContentType = "text/plain";
            HttpRequest request = context.Request;
            int id = Convert.ToInt32(context.Request.QueryString["id"]);
            PsbE = Psb.GetInfo(id);
            Byte[] img = PsbE.Psblcon;
            ms = new MemoryStream(img);
            Image icon = Image.FromStream(ms);
            int thumbnailWidth = TypeParse.StrToInt(request["tw"],-1);
            int thumbnailHeight = TypeParse.StrToInt(request["th"],-1);
            string mode = request.Params["mode"].ToString();
            string module = request.QueryString["module"].ToString();

            string tablename = module + "_ATTACHMENT";
            WEIP.Sys.Attachment attach = new WEIP.Sys.Attachment("", tablename, true, "");
            ms.Close();

            //背景色
            WEIP.Site.Thumbnail.BgColor color = WEIP.Site.Thumbnail.BgColor.White;

            if (mode == "0")
            {
                color = WEIP.Site.Thumbnail.BgColor.White;
            }
            if (thumbnailWidth == -1 && thumbnailHeight == -1)
            {
                ImageFormat thisFormat = icon.RawFormat;
                if (thisFormat.Equals(ImageFormat.Gif))
                {
                    context.Response.ContentType = "image/gif";
                }
                else
                {
                    context.Response.ContentType = "image/jpeg";
                }
                Bitmap outBmp = new Bitmap(icon);
                outBmp.Save(context.Response.OutputStream, thisFormat);
            }
            else
                new WEIP.Site.Thumbnail().GetSmallImage(context.Response, icon, thumbnailWidth, thumbnailHeight, color);

            //写新图
        }
        catch
        {

        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

}

asp页面




/asp:HyperLink
数据加载时的方法
this.PImage.ImageUrl = "~/Staff/Center/StffIcon.ashx?id=" + Id + "&tw=150&th=150&mode=0&module=OUTSIDE_SITE";
            this.LinkUrl.NavigateUrl = "~/Staff/Center/StffIcon.ashx?id=" + Id + "&mode=0&module=OUTSIDE_SITE";
  • 写回答

3条回答 默认 最新

  • lhl_lqc 2015-04-02 09:17
    关注

    public System.Drawing.Image ReturnPhoto(byte[] streamByte)
    {
    System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte);
    System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
    return img;
    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制