您的位置:首页 > 理论基础 > 计算机网络

wcf http 返回图片

2012-11-13 11:35 183 查看
做项目时候用wcf 返回图片,从官网上找了找一次只能返回一张图片,但是一直查不到返回多个图片的方法,ios 可以异步加载看速度也可以

,先记录一下等以后用解决了再发

http://msdn.microsoft.com/en-us/library/cc681221(v=vs.85).aspx

[ServiceContract]
public interface IImageServer
{
[OperationContract, WebGet]
Stream GetImage(int width, int height);
}

public class Service : IImageServer
{
public Stream GetImage(int width, int height)
{
Bitmap bitmap = new Bitmap(width, height);
for (int i = 0; i < bitmap.Width; i++)
{
for (int j = 0; j < bitmap.Height; j++)
{
bitmap.SetPixel(i, j, (Math.Abs(i - j) < 2) ? Color.Blue : Color.Yellow);
}
}
MemoryStream ms = new MemoryStream();
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";//可以换成其它格式的图片
return ms;
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: