0

在我的 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

现在这实际上让我更接近我想要的,但不是显示嵌套在其中的图像的页面,它只是将它抓取的第一张图像流式传输到我的浏览器 - 不是我想要的。我希望所有图像都嵌套在页面上预先存在的内容框中。

4

2 回答 2

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
于 2013-11-14T11:39:37.350 回答
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

希望这可以帮助遇到此问题的任何人!

于 2013-11-14T16:38:08.090 回答