我正在调用一个webservice,它以字节数组的形式返回未知数量的图像。 (我不能改变这一点)在页面上动态显示从字节数组派生的图像
我需要在一个aspx网页上显示每个图像。
我目前使用的是Microsoft.Web.GeneratedImage控件; http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16449 显示图像。
我遇到的问题是,由于控件调用一个单独的代码文件来加载图像内容,我使用会话状态来存储bytearray,我不是过分高兴。
下面是我测试项目中的一些代码;
Private Sub btnGetChart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetChart.Click
Dim reportHub As New HubWrapper
Dim repCharts() As ReportHub.Chart = reportHub.ReportHubChart(Me.ddlReports.SelectedValue, ViewState("params"))
For Each chart As ReportHub.Chart In repCharts
Dim sessionKey As String = "img" & System.Guid.NewGuid().ToString
Dim imgParam As New Microsoft.Web.ImageParameter()
imgParam.Name = "sessionVar"
imgParam.Value = sessionKey
Session(sessionKey) = chart.ChartData
Dim img As New Microsoft.Web.GeneratedImage
img.ImageHandlerUrl = "~/chartImageHandler.ashx"
img.Parameters.Add(imgParam)
phChart.Controls.Add(img)
Next
End Sub
<%@ WebHandler Language="VB" Class="chartImageHandler" %>
Imports System
Imports System.Collections.Specialized
Imports System.Drawing
Imports System.Web
Imports Microsoft.Web
Public Class chartImageHandler
Inherits ImageHandler
Implements IRequiresSessionState
Public Sub New()
MyBase.New()
'Set caching settings and add image transformations here
'EnableServerCache = True
End Sub
Public Overrides Function GenerateImage(ByVal parameters As NameValueCollection) As ImageInfo
Dim byteArry As Byte() = CType(HttpContext.Current.Session(parameters("sessionVar")), Byte())
HttpContext.Current.Session.Remove(parameters("sessionVar"))
Return New ImageInfo(byteArry)
End Function
End Class
什么是实现这一目标的最优雅的方式?
任何输入欢迎!
编辑:其他信息;
- 来自web服务的图像是来自SQL Reporting Services的 。
- 图像一般会变化 所有时间都在变化(没有真正的 缓存要求)。
- 图像将是用户特定的。
- webservice每页仅调用一次。
- 我从 会话状态的产生 图像后实际处置图像的使用它,因为不会 所需的图像获得 而再次观看。
哦,IE <8的问题没有打扰我。 – GordonB 2009-05-15 07:27:52
工作很好.... IE唯一的问题是数据uri的大小限制。 Convert.ToBase64String(imageToDisplay).Length <32768 etc等 – GordonB 2009-05-15 09:56:51