English 中文(简体)
展示协会的形象。 NET C#
原标题:Displaying image in ASP.NET C#
  • 时间:2012-01-13 16:51:22
  •  标签:
  • c#
  • image
  • io

我正在将基地64的代码转换成图像,我正在以下列方式挽救和展示这一形象。

var kpin = Base64ToImage(TextBox1.Text);
kpin.Save(@"e:myim.png");
Image1.ImageUrl = @"e:myim.png";

并且

public Image Base64ToImage(string base64String)
{
    byte[] imageBytes = Convert.FromBase64String(base64String);
    MemoryStream ms = new MemoryStream(imageBytes, 0,
      imageBytes.Length);
    ms.Write(imageBytes, 0, imageBytes.Length);
    Image image = Image.FromStream(ms, true);
    return image;
}

而这一过程是很出色的,但我不需要在硬盘中保存形象。 如何直接展示这种形象,而不节约硬盘和检索。

最佳回答

而不是制定《形象》。 形象与你形象的道路相去,你可以做几个事情:

  1. Use an img tag with the Base64 data in it directly - http://www.sweeting.org/mark/blog/2005/07/12/base64-encoded-images-embedded-in-html Not all browsers support this.
  2. Create an Action or Webform (depending on whether you re using ASP.NET MVC or not) that takes as input whatever you need to either retrieve or generate the Base64 encoded data, and then set the response headers to serve the correct content type (image/png or something) and write the image directly to the Response.OutputStream (or use ContentResult in ASP.NET MVC). Tons of examples via Stackoverflow on how to do either.

-

问题回答

a. 完全用图像标的双向双向,仅指:

public void Base64ToResponse(string base64String)
{
    Response.ContentType = "text/png"; //or whatever...
    byte[] imageBytes = Convert.FromBase64String(base64String);
    Response.OutputStream(imageBytes, 0, imageBytes.Length);
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签