Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从服务中获取映像_C#_Javascript_Asp.net Mvc_Service_Asp.net Mvc 4 - Fatal编程技术网

C# 从服务中获取映像

C# 从服务中获取映像,c#,javascript,asp.net-mvc,service,asp.net-mvc-4,C#,Javascript,Asp.net Mvc,Service,Asp.net Mvc 4,我使用MVC4、Razor和C。我想要服务,例如: [WebGet] [OperationContract] public string Get(int id) { PictureManager m = new PictureManager(); Picture p = m.Load(id); return Convert.ToBase64String(p.Trunk); } 其中: public byte[] Trunk { get { return _trunk; } } 在

我使用MVC4、Razor和C。我想要服务,例如:

[WebGet]
[OperationContract]
public string Get(int id)
{
  PictureManager m = new PictureManager();
  Picture p = m.Load(id);
  return Convert.ToBase64String(p.Trunk);
}
其中:

public byte[] Trunk { get { return _trunk; } }
在客户端,我希望以同样的方式使用它:

<img src="http://MyService/MyPictures/Get?id=21"> 


有同样的能力吗?或者我需要使用一些JavaScript在客户端显示图片?您能告诉我方向吗?

如果您的图像是jpeg格式,请从代码中返回此信息

return "data:image/jpeg;base64," + Convert.ToBase64String(p.Trunk);

大多数情况下,请尝试返回文件流结果,这是一个非常糟糕的设计。这将在每次呈现html时生成图像的base64版本。例如,如果使用两次图像,图像将渲染两次。这将为html页面增加巨大的网络过载。如果您创建了一个专用的图像服务端点,您将能够添加缓存、控制html标题等。您可以通过阅读获取下降示例。