public HttpResponseMessage GetVerifyCode() { var verifyCode = VerificationCodeUtils.Create(4); if (!verifyCode.Check()) { return(null); } var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(verifyCode.ImageBytes) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg"); return(response); }
private void GenerateVerifyCode() { //获取验证码 string file = new DirectoryInfo(ClientContext.BaseDirectory).FullName.TrimEnd() + "/verifycode.jpg"; var code = VerificationCodeUtils.Create(); vmLogin.VerifyCodeTarget = code.Code; using (var stream = new MemoryStream(code.ImageBytes)) { var img = System.Drawing.Image.FromStream(stream); var fileInfo = new FileInfo(file); if (!fileInfo.Directory.Exists) { fileInfo.Directory.Create(); } img.Save(file); } }