在我的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.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
现在这实际上让我更接近我想要的东西,但是它不是显示嵌入其中的图像的页面,而是将其抓取到浏览器的第一个图像流式传输 - 不是我想要的。我希望所有图像都嵌套在页面上预先存在的内容框中。
答案 0 :(得分:0)
试试这个:
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
答案 1 :(得分:0)
最后让它最终工作,首先我创建了一个名为'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
然后我在我的页面中创建了一个转发器,其中包含一个像这样的对象模板
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="<%#Container.DataItem%>"/><br />
</ItemTemplate>
</asp:Repeater>
并在put后面的代码中
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
希望这有助于遇到此问题的任何人!