/// <summary> /// 获取二维码 /// </summary> /// <param name="size">编码测量度,值越大生成的二维码图片像素越高,尺寸越大(建议设置为4)</param> /// <returns></returns> [Route("ThirdParty/GetQRCode")] public HttpResponseMessage GetExamInfoQRCode( int size) { HttpResponseMessage message = new HttpResponseMessage(); try { string Url = "www.baidu.com" //生成图片 Bitmap image = CommonUtil.CreateImgQRCode(examInfoUrl, size); //保存图片数据 MemoryStream stream = new MemoryStream(); image.Save(stream, ImageFormat.Jpeg); message = Request.CreateResponse(HttpStatusCode.OK); message.Content = new ByteArrayContent(stream.ToArray()); //data为二进制图片数据 message.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); return message; } catch (Exception ex) { //这里可以记录错误日志,然后返回一个默认的错误图片增强友好性 message.Content = new ByteArrayContent(null); //data为二进制图片数据 message.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); return message; } }