psean445
psean445

Reputation: 1

asp.net display image using byte

The following code gets the images name on page load:

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim getImg As New GetImage.SoapClient
            Dim ImageService As New Service.serviceClient
            Dim imageName As String = ImageService.getImgName(imageID)
            Dim binaryImage As Byte() = getImg.getImgDisplay(imageName )
            Image123.ImageUrl = "data:image/png;base64," & imageName 
        End If
    End Sub

            <asp:Image ID="Image123" runat="server" Visible="true" />

In the following line of code I have received the image name "imageName":

  Dim binaryImage As Byte() = getImg.getImgDisplay(imageName )

How can I display this on HTML as it is a byte?

Upvotes: 0

Views: 680

Answers (1)

Cam Bruce
Cam Bruce

Reputation: 5689

byte[] is not equal to base64, which is what format the image needs to be if you're trying to embed on the page. You need to convert the byte[] in order to embed the image into the html.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim getImg As New GetImage.SoapClient
            Dim ImageService As New Service.serviceClient
            Dim imageName As String = ImageService.getImgName(imageID)
            Dim binaryImage As Byte() = getImg.getImgDisplay(imageName )
            Image123.ImageUrl = "data:image/png;base64," & Convert.ToBase64(binaryImage)
        End If
    End Sub

Upvotes: 1

Related Questions