There was such a problem in the work. At first, it was easy to get a picture of the byte[], you can convert it into an in-memory picture object (such as System.Drawing.Image), and then assign to the page image control. Try to find that it is not done at all. Search the network and sort out two ways to implement it.
Sample code here!
First, introduce a new page. Aspx,image control URL points to this page
This page imagesource.aspx only one thing: Writes the byte[representing the picture] to the HTTP output stream.
1 response.binarywrite (imgbytes);
The effect of this page is to display only the picture itself.
Causes the ImageUrl property of the image control to point to the page.
1 string. Concat ("imagesource.aspx?name=""lighthouse");
Feature implementation. This kind of method is relatively simple, but the disadvantage is to introduce a seemingly redundant page imagesource.aspx. To avoid this, there is a second approach.
Second, the introduction of HttpHandler, specifically to handle the picture loading request
The image control still points to a page URL through the ImageUrl property, but the page does not really exist. The request was referred to handler for processing.
1 < httphandlers > 2 < verb= "*" path= "imagevirtualsource.aspx" type= " Imagebytesshowsample.imagevirtualsourcehandler "/>3</ httphandlers>
The work done in Imagevirtualsourcehandler is essentially the same as in the previous imagesource.aspx, mainly the output of the picture byte[] to the HTTP stream.
1 Public voidProcessRequest (HttpContext context)2 {3 varImgname = context. request.querystring["name"];4 varLightimg = Image.FromFile (string. Concat ("e:\\cspro\\imagebytesshowsample\\imagebytesshowsample\\", Imgname,". jpg"));5 6byte[] Imgbytes =imagetobytes (lightimg);7 8 context. Response.BinaryWrite (imgbytes);9}
Special attention:
If run with integrated environment (vs Debug Run),<system.web>
1 <system.webserver>2 <handlers>3 <Addname= "Virtualimagehandler"verb="*"Path= "Imagevirtualsource.aspx"type= "Imagebytesshowsample.imagevirtualsourcehandler"/>4 </handlers>5 </system.webserver>
Image control displays a picture that exists as a byte[] byte array