How to add multiple TIFF files to ASP.NET output stream
I have a requirement for displaying one or more TIFF files on the same ASPX page. To add to the complexity, some of the files can be multiple page TIFF files. IE6-8, FF 3.X, Google Chrome support required.
I have had some success displaying any one image by converting the file to a MemoryStream and sending to to the Response via BinaryWrite, but can not seem to find the way to supp开发者_如何转开发ort multiple files/pages. What is the best way to accomplish this?
Each request is always for a single "object", either a page or image or whatever else. To output multiple images for a single request the only way that I can think of is to stitch the images together into one giant image and push that out.
Rather than spending time converting to a MemoryStream, try just using Response.WriteFile()
Also, the way to show multiple images on an aspx is, of course, by simply putting multiple img
or asp:Image
tags on the page and let the browser handle making new requests for those images. Do not try to write multiple images out to the same request. This likely means you need to create a new aspx for (or better, ashx HttpHandler) to handle these requests.
TIFF is not a supported format in browsers, you need to convert your images to something else, such as JPEG before sending them to the browser. Also you need to send them one at a time. Put several img-tags in your aspx-page to get all images. Also you need to create a interface for turning pages in the multi-page images and also send each page as a separate request to/from the server.
You will not be able to send multiple pictures back in one response. TIF does support multiple pages within the same image though but it doesn't sound like that is what you want.
What you will need to do is build up some type of image handler (eg. myimage.ashx) and that returns one image only. Then in the calling page have multiple img
tags that link to the ashx with the ID of the image you want. The ashx file will then handle each request individually but your main aspx or html page will be incharge of displaying them however is required.
I'm surprised no one has said this yet, and it may not be relevant to your situation, but you can do this fairly easily with JavaScript. You would make an Ajax call, and from it you'd return the data for all of the images. The return data could be a JSON array with base64 encoded data for each image. Then, script in your page would need to loop over all the images in the JSON array, and insert each image into the DOM of the page.
I don't know if you're familiar with JavaScript or not, and if you're already doing some Ajax. If not, maybe it's not the solution for you. But if you're open to those technologies, then this is a fairly easy task to pull off. For example, with JQuery, this would be really straightforward.
精彩评论