簡體   English   中英

在ASP.NET中使用文本和圖像即時創建圖像

[英]Create image on the fly with Text and images in asp.net

有人在asp.net中有任何示例可以動態創建圖像嗎? 我用Google搜索並找到了一些文章,但所有內容都討論了如何將文本轉換為圖像。 但是我想通過加入一些小的縮略圖和文本來創建圖像。

任何幫助都非常感謝。

謝謝

你可以嘗試這樣的事(抱歉不知道C#)

Public Function CreateImageFromThumbnails(ByVal lstImages As List(Of Image)) As Bitmap

    Dim width As Integer = 0
    Dim height As Integer = Integer.MinValue
    For Each img In lstImages
        If img.Height > height Then
            height = img.Height
        End If
        width += img.Width
    Next

    Dim bmp As New Bitmap(width, height)
    Using fnt As New Font("Verdana", 14)
        Using gfx As Graphics = Graphics.FromImage(bmp)
            Dim x As Integer = 0
            For Each img As Image In lstImages
                gfx.DrawImageUnscaled(img, x, 0)
                x += img.Width
            Next
            gfx.DrawString("Sample String", fnt, Brushes.White, 0, 0)
        End Using
    End Using

    Return bmp

End Function

Public Sub CreateImage()

    Dim lstImages As New List(Of Image)
    lstImages.Add(Bitmap.FromFile("thumbnail1.png"))
    lstImages.Add(Bitmap.FromFile("thumbnail2.png"))
    lstImages.Add(Bitmap.FromFile("thumbnail3.png"))
    lstImages.Add(Bitmap.FromFile("thumbnail4.png"))
    Using result As Bitmap = CreateImageFromThumbnails(lstImages)
        result.Save("c:\result.bmp")
    End Using

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM