Skip to main content Skip to footer

How to Display SQLite BLOB Images in a .NET Reporting Application

From time to time, we get questions on how to show images from SQLite. In this blog, we'll go over how to display such images in your .NET reports created with ActiveReports.NET.

We will use the SQLite Data Provider, which was introduced in ActiveReports.NET 16, to bind to our employees.sqlite database: 

Report Data Source

We'll add a dataset as usual. Please see this page if you're unfamiliar with data binding in ActiveReports.NET. 

At this point, all you must do is set the following properties for the image control:

  • Source: Database
  • Value: =Fields!employeeImage.Value

If, however, you are using a prior version of ActiveReports.NET (v15 or earlier), we need a bit of code to convert the BLOB image from your SQLite database. Here's a sample code:

Public Function BlobToByte(ByVal x) As Byte()
    Dim str As String = BlobToString(x)
    Return System.Text.Encoding.Default.GetBytes(str)    
End Function
 
Public Function BlobToString(ByVal x) As String    
    Dim str As String = HexToString(x.Substring(2, x.Length - 3)) 'remove envelope sqlite 
    Return str.Substring(78, str.Length - 79) ' remove header Bitmap Image Paint.Picture
End Function
 
Function HexToString(ByVal hex As String) As String
    Dim text As New System.Text.StringBuilder(hex.Length \ 2)
    For i As Integer = 0 To hex.Length - 2 Step 2
        text.Append(Chr(Convert.ToByte(hex.Substring(i, 2), 16)))
    Next
    Return text.ToString
End Function

Place this code in the “Script” section of our RDL report:

RDL Report

Select the Image control on the design surface, and change its “Value” Property to:

=code.BlobToByte(Fields!Picture.Value)

This expression tells the RDL report to look in the Script section for a Function named BlobToByte, which takes the BLOB image as a parameter.

Here's how the report looks in the preview:

Report Preview

To see the complete implementation, download the zip file here: SqliteBlob.zip

Learn more about ActiveReports.NET features by visiting our Online Demos

comments powered by Disqus