Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert Image to Data URI for Html with C#?

Tags:

html

c#

I need convert image to Data URL (embedding Image) in the Win-application for HTML and I need Data URL (embedding Image) to image.

like image 832
hashi Avatar asked Jul 26 '11 06:07

hashi


People also ask

What is data URI of image?

The data URI scheme is a uniform resource identifier (URI) scheme that provides a way to include data in-line in Web pages as if they were external resources. It is a form of file literal or here document.

How can I get URI data?

Right-click the image's URL (the cursor will turn into a hand) and choose Open link in Resources Panel. Right-click the image in the Resources Panel and choose Copy image as Data URL. Paste the Data URI wherever you need it.


1 Answers

        public static string GetDataURL(string imgFile)         {             return "<img src=\"data:image/"                          + Path.GetExtension(imgFile).Replace(".","")                         + ";base64,"                          + Convert.ToBase64String(File.ReadAllBytes(imgFile)) + "\" />";         } 
like image 148
Ankur Avatar answered Sep 16 '22 23:09

Ankur