Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.67 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Displaying image in ASP.NET C#
  2. var kpin = Base64ToImage(TextBox1.Text);
  3. kpin.Save(@"e:myim.png");
  4. Image1.ImageUrl = @"e:myim.png";
  5.        
  6. public Image Base64ToImage(string base64String)
  7. {
  8.     byte[] imageBytes = Convert.FromBase64String(base64String);
  9.     MemoryStream ms = new MemoryStream(imageBytes, 0,
  10.       imageBytes.Length);
  11.     ms.Write(imageBytes, 0, imageBytes.Length);
  12.     Image image = Image.FromStream(ms, true);
  13.     return image;
  14. }
  15.        
  16. public void Base64ToResponse(string base64String)
  17. {
  18.     Response.ContentType = "text/png"; //or whatever...
  19.     byte[] imageBytes = Convert.FromBase64String(base64String);
  20.     Response.OutputStream(imageBytes, 0, imageBytes.Length);
  21. }