Convert Binary data to image, Save and retrieve image from binary data c#

Get your PDF copy

Convert binary Data to Image: This article will demonstrate how to display an image, save and retrieve an image from binary data typed saved in Ms-SQL database  i.e convert binary data into image in C#. Mostly in many application where we use BioMetric hardware or webcam to capture images, we save those images into the database in binary format. Now when we need to display image from binary data from our database (MSSQL server) we have to add the generic handler.

Code to save and retrieve image ( binary data saved ) as below:

Add a .ashx page that you’ll target as an image URL. Then you need to write the byte array as response stream in the ProcessRequest method inside that handler as shown in below code snippet.


Default page.aspx.cs

Conclusion: In this article, we learn how to save and convert the image into binary data and save it to the database (MS SQLserver). Also how to retrieve binary data from database and display image in C# WebApplication. I.e. converting binary data (bytes) to image

 You can also check these articles:

  1. Upload and Resize image using Dropzone Js C#.
  2. Preview Image before upload in jQuery, HTML5 FileReader().
  3. Chart.js Create Pie Chart with database Jquery Ajax C#.
  4. Generic Handler ashx file: Post send JSON data in C#.
  5. jQuery Ajax JSON Example in with SQL database.

Hope you enjoyed this tutorial. If you have any recommendations, please let us know what you think in the comment section below! See you again next time!

Get your Printable Copy