我尝试将 C# Web 应用程序的一部分转换为 C# 库。
我使用了一个 Response 对象,但是这个对象在 C# 库中不再被识别。
这里是一些代码:
// Create a CAPTCHA image using the text stored.
CaptchaImage ci = new CaptchaImage(textCaptcha, 200, 50, "Century Schoolbook");
// Change the response headers to output a JPEG image.
this.Response.Clear();
this.Response.ContentType = "image/jpeg";
// Write the image to the response stream in JPEG format.
ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg);
// Dispose of the CAPTCHA image object.
ci.Dispose();
如何使用 Response 对象,或者用更好的东西来改变它? 谢谢
请您参考如下方法:
响应对象代表您发送给客户端的流。在桌面应用程序中没有这样的概念,因为您的程序就是客户端,所以您没有流来发送客户端。在上面的示例中,您正在将 captchaImage 写入流中,该图像将显示在客户端浏览器上。如果那是你唯一的意图,你可以使用 picturebox控制显示图像。如果您只需要保存图像,您可以按照将图像写入响应流的相同方式将图像写入文件流。
