wcf http 返回图片
生活随笔
收集整理的這篇文章主要介紹了
wcf http 返回图片
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
做項目時候用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 返回图片的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Jmeter(一)-精简测试脚本
- 下一篇: keycode对应主要键的关系