本文介绍了如何转换为System.Drawing.Image到system.web.ui.webcontrols.image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用字节来存储图像,并能够将其转换为System.Drawing.Image对象,但不知道如何使其网页

I use to store image in bytes and able to convert it to system.drawing.image but not sure how to render it on page

感谢

推荐答案

您可以创建ASPX页面,将返回图像文件作为字节数组相应的​​邮件头信息,得到的图像,你将能够调用这个页面如 imagemanager.aspx?imgid = 31337

You can create ASPX page that will return image file as byte array with appropriate headers information, to get image you will be able to call this page like imagemanager.aspx?imgid=31337

然后在 system.web.ui.webcontrols.image 控制设置的ImageUrl 属性您的主页您脚本路径:

Then in your main page in system.web.ui.webcontrols.image control set ImageUrl property to your script path:

ctrlImage.ImageUrl = "imagemanager.aspx?imgid=31337";

下面是实例方法的输出你imagemanager.aspx图片:

Here is example of method to output you image in imagemanager.aspx:

    private void TransmitBytes(byte[] bytes, string outFileName)
    {
        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + outFileName);
        Response.AddHeader("Content-Length", bytes.Length.ToString());
        Response.ContentType = "image/jpeg";
        Response.BinaryWrite(bytes);
        Response.End();
    }

这篇关于如何转换为System.Drawing.Image到system.web.ui.webcontrols.image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 08:03