public void DrawImage(string imageURL)
{
// convert image to bytes array
WebClient wClient = new WebClient();
byte[] imageBytes = wClient.DownloadData(@imageURL);
// create memory stream of bytes array and convert image to base 64 and display it
MemoryStream imgStream = new MemoryStream(imageBytes);
ImageBox.ImageUrl = "data:image/jpg;base64," + Convert.ToBase64String(imgStream.ToArray(), 0, imgStream.ToArray().Length);
}
*ImageBox is a image control on the page.
*Sample call: DrawImage("c:\windows\image.jpg")
{
// convert image to bytes array
WebClient wClient = new WebClient();
byte[] imageBytes = wClient.DownloadData(@imageURL);
// create memory stream of bytes array and convert image to base 64 and display it
MemoryStream imgStream = new MemoryStream(imageBytes);
ImageBox.ImageUrl = "data:image/jpg;base64," + Convert.ToBase64String(imgStream.ToArray(), 0, imgStream.ToArray().Length);
}
*ImageBox is a image control on the page.
*Sample call: DrawImage("c:\windows\image.jpg")