ASP.NET VB在运行时显示新图像
在我的VB项目中,我已经有了检索指定目录中每个图像路径的函数,然后我使用ASP.NET VB在运行时显示新图像,asp.net,vb.net,image,runtime,Asp.net,Vb.net,Image,Runtime,在我的VB项目中,我已经有了检索指定目录中每个图像路径的函数,然后我使用 Dim Pics() As String = piccom.GetPictures("The\Dir") For Each pic In Pics If Not pic = "" Then Dim bmp As New Bitmap(pic) Dim Width As Integer = bmp.Width Dim Height As Integer = bmp.He
Dim Pics() As String = piccom.GetPictures("The\Dir")
For Each pic In Pics
If Not pic = "" Then
Dim bmp As New Bitmap(pic)
Dim Width As Integer = bmp.Width
Dim Height As Integer = bmp.Height
Else
Exit For
End If
Next
要遍历所有返回的图像,我需要能够在运行时在页面的主要内容中显示这些图像,如何在运行时显示这些图像
编辑:
我一时兴起,试了一下
For Each pic In Pics
If Not pic = "" Then
Dim bmp As New Bitmap(pic)
Dim Width As Integer = bmp.Width
Dim Height As Integer = bmp.Height
Response.ContentType = "image/jpeg"
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
Else
Exit For
End If
Next
现在,这实际上让我更接近我想要的,但它没有显示嵌套在其中的图像的页面,而是将它抓取的第一个图像流式传输到我的浏览器中,而不是我想要的。我希望所有图像都嵌套在页面上预先存在的内容框中。尝试以下操作:
Dim Pics() As String = piccom.GetPictures("The\Dir")
For Each pic In Pics
If Not pic = "" Then
Dim bmp As New Bitmap(pic)
Dim Width As Integer = bmp.Width
Dim Height As Integer = bmp.Height
picImage.Image = bm
picImage.SizeMode = PictureBoxSizeMode.AutoSize
Else
Exit For
End If
Next
最后终于让它工作了,首先我创建了一个名为“image.aspx”的新页面,并将其放入其中
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class image
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim query As String = Request.QueryString("i")
Dim maxw As String = Request.QueryString("maxw")
Dim maxh As String = Request.QueryString("maxh")
If Not query = "" Then
Dim file = AppDomain.CurrentDomain.BaseDirectory + "\DIRWHEREPICTURESARE" + query
Dim bmp As New Bitmap(file)
Response.ContentType = "image/jpeg"
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
End If
End Sub
End Class
然后,我在我的页面中创建了一个repeater,其中有一个对象模板,如下所示
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="<%#Container.DataItem%>"/><br />
</ItemTemplate>
</asp:Repeater>
希望这能帮助任何遇到这个问题的人 我不想更改预先存在的图像框,我想创建一个新的图像框,以便目录中的所有图像都可以显示,而不仅仅是一个。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Pics() As String = piccom.GetPictures("Image\Directory")
Dim aList = From fileName In Pics
Repeater1.DataSource = aList
Repeater1.DataBind()
End Sub