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

  

相关文章:

  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2021-11-24
猜你喜欢
  • 2022-12-23
  • 2021-08-22
  • 2021-10-04
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
相关资源
相似解决方案