Notice how the data URL has data:image/png;base64 at the beginning.
This way the browser knows that the src attribute value itself contains the image data.
At times, however, you need to display images that are available as raw binary data.Consider, for example, that you are building a Captcha system that generates images on the fly.These images won't reside on the server as physical files.It has the greatest potential impact on an application's performance, out of all the other features in ASP. NET developers to accept the additional overhead of building sites using rather heavy controls like Data Grids without fear that performance will suffer too much.In order to see the most benefit from caching in your applications, you should consider ways of implementing caching at all levels of your program.Make sure to change the image type (/ / etc.) as per your needs, Then a View Bag variable named Image Data is set to this data URL.The Index view makes use of this View Bag property as shown below: The following figure shows a sample run of the above code: Let's see another technique to achieve the same result.Once the image content is read as a byte array, it is converted into a Base64 string using To Base64String() method of Convert class.This Base64 string is used to form a data URL as shown.It then uses File() method of the Controller base class to send the contents to the caller.The first parameter is a byte array that represents the file content and the second parameter indicates the MIME content type. He is a published author and has authored or co-authored books for Apress and Wrox press.