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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵