Big Monty
asked on
create DATA URI's for image tags
I have a need to create data URI's for my images so that I can set the SRC attribute as the data URI in an IMAGE tag. I found the following function online, but am getting the error "URI formats are not supported.". Any suggestions on how to fix this?
imgFile is in the format of:
http://www.abc.com/someFileName.jpg
here's my code:
imgFile is in the format of:
http://www.abc.com/someFileName.jpg
here's my code:
public static string GetDataURI(string imgFile)
{
return "<img src=\"data:image/"
+ Path.GetExtension(imgFile).Replace(".", "")
+ ";base64,"
+ Convert.ToBase64String(File.ReadAllBytes(imgFile)) + "\" />";
}
ASKER
i get it when I run my console program in Visual Studio.
The code is fine. Please post your console app's code.
ASKER
The console's code is literally one line, calling this function (I made a test console program to test this individual function). When I step through my code in VS, and I hit F10 right up to the return line, that's when I get the error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it works if you give it a physical path, yes. I was trying to give it a web url. Fortunately, I was able to find a way to get the physical path to it, so I have everything I need right now.
Where do you get this error? on the page? compile time? or somewhere else?
Regards,
Chinmay.