做項(xiàng)目時(shí)候用wcf 返回圖片,從官網(wǎng)上找了找一次只能返回一張圖片,但是一直查不到返回多個(gè)圖片的方法,ios 可以異步加載看速度也可以
,先記錄一下等以后用解決了再發(fā)
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 無法注冊 另一應(yīng)用程序正在使用 TCP 端口 80