Skip to main content

How to Display Images in the PictureBox used in Windows Apps or Mobile Based Apps.

Normally in windows based application there is a requirement to display image in the picture box which has been read from SQL Server. The image is stored in binary format in SQL Server. So we have to convert raw format read from database into bytes and then use stream to load the bytes in the format of an image. The following code shows how to display the image in the picture box in VB.NET

   Dim vbyte() As Byte = CType(myDatarow("Snap"), Byte())

   Using ms As New IO.MemoryStream(vbyte)
   PictureBox1.Image = New Bitmap(ms)
   PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
   End Using

In the above code, myDatarow is the object of DataRow class that is read and “Snap” is the name of the column in the database that stores the image.

1. So firstly we convert the read image from SQL Server into Bytes array.

2. Then we use MemoryStream to read the bytes into the stream and load the same bytes in the format of image in the PictureBox.

3. We can also the “SizeMode” Property to StretchImage or any other as required.

The above code can be used in the Windows Based application or Windows Mobile Phone Application.

Comments

Vinay Anand said…
Jai Ho Maan Gaye Sir G