开发者

How to convert system.drawing.image to system.web.ui.webcontrols.image

I use to store image in bytes and able to convert it to system.drawing.image but not sure how to render it o开发者_运维技巧n page

Thanks


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

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";

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 represents image or picture that you can render, print, save to file, resize, create thumbnail from etc. But System.Web.UI.WebControls.Image is a web control that you can use to show images on web pages.

To show dynamically created image on webpage you need some handler or other mechanism that sends image to calling page.

Here is an article on 4guysfromrolla that explains this concept.

Here is another one on developerfusion.com in C#

I found this very detailed article on MSDN by Scott Mitchel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜