将图像数据传递给 JS 图像 URL 参数的客户端

Passing image data to client-side for JS image URL parameter

我将图像数据存储在数据库中。我想在后面的代码中检索该数据并将其传递到 aspx 页面,以便它可以用作某些 JS 中的参数。

通常,我会在 HTML 中包含一个隐藏字段,并在页面加载时从后面的代码中填充我想要的任何数据,然后在 JS 中获取它。 问题是 JS 函数需要图像 URL 而不是 Byte(),这就是图像在数据库中的存储方式。

如何将图像数据转换成JS可以使用的东西?

这里的JS函数供参考:

function onVrViewLoad() {
    var vrView = new VRView.Player('#vrview', {
        image: 'images/myImage.jpg', //image URL goes here
        width: 800,
        height: 700,
        is_stereo: false
    });
}

谢谢!

正如@Igor 在评论中所建议的,我创建了一个单独的页面,returns 响应中的文件流:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim rs As SqlDataReader = SqlHelper.ExecuteReader(ConfigurationManager.AppSettings("connString"), "spGetAttachment", Request.QueryString("id"))
    rs.Read()
    Response.Buffer = True
    Response.Clear()
    Response.Expires = 0
    Response.ContentType = rs("ContentType")
    Dim File() As Byte = rs.GetValue(8)
    Response.BinaryWrite(File)
    Response.End()
End Sub

然后在原始页面上,我将图像的 URL 设置为我新创建的 Viewer.aspx:

function onVrViewLoad() {
    var imgID = document.getElementById("<%= hfImgID.ClientID %>");

    var vrView = new VRView.Player('#vrview', {
        image: "AttachmentViewer.aspx?id=" + imgID.value,
        width: 780,
        height: 580,
        is_stereo: false
    });
}