Forum Discussion

Tengmin123's avatar
Tengmin123
Frequent Visitor
5 years ago

Cannot display image in report builder from byte array or hex string

Hi, all,

 

I have a byte array (image) in json format in sql db. I extract the image out and also in json format. my query is:

SELECT thumbNail FROM Table
cross apply openjson(CMD_LIST,'$.queueMessagePages')
with
(pageNo Int '$.pageNo',
[thumbNail] nvarchar(max) as JSON
) as jsonsvalues where ...

 Then I get the thumbnail in nvarchar(max). 

In the report builder, I customize a function to convert the byte array into hex string. the function is like:


Function ToHexString(ByVal bytes() As Integer) As String
Dim strB As New System.Text.StringBuilder
Dim ints(bytes.Length) As Integer
Dim N as long
For N = 0 To bytes.Length - 1
If bytes(N) < 0 Then
ints(N) = bytes(N) + 256
Else
ints(N) = bytes(N)
End If
Next

For N = 0 To ints.Length - 1
If ints(N) < 16 Then
strB.Append("0" & Hex$(ints(N)))
Else
strB.Append(Hex$(ints(N)))
End If
Next

ToHexString ="0x" & Replace(strB.ToString().ToUpper(), " ", "")
Return ToHexString
End

 

I tried to run this function in vb,net can get the hex string correctly. but cannot get the image in report builder.

Please help to visualize the image in report builder if you have any experience. Thank you!

v-janeyg-msft 

6 Replies

  • AbhiSSRS's avatar
    AbhiSSRS
    Solution Sage

    The rdl supports Byte Array so you do not need to convert to hex! We have been converting the hex to bytearray if at all! Try to put this on a Dataset field and bind that to the image control. Also just to make sure the image mime is as of the original one.

     

     

     

    • Tengmin123's avatar
      Tengmin123
      Frequent Visitor

      Thank you for your reply.  but my byte array is saved as varchar(max) in database, it is a string with byte array value. is it still ok for report builder to visualize it?

      • AbhiSSRS's avatar
        AbhiSSRS
        Solution Sage

        Yeah it should work! try adding this convert 

        Convert.FromBase64String