做项目时候用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; } } |

博主下一篇:解决 wcf HTTP 无法注册 另一应用程序正在使用 TCP 端口 80