index.ashx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <%@ WebHandler Language="C#" Class="index" %>
  2. using System;
  3. using System.Web;
  4. using ZXing;
  5. using ZXing.Common;
  6. using System.Drawing;
  7. using System.Drawing.Imaging;
  8. public class index : IHttpHandler
  9. {
  10. public void ProcessRequest(HttpContext context)
  11. {
  12. context.Response.ContentType = "text/plain";
  13. EncodingOptions eo = new EncodingOptions();
  14. eo.Width = 400;
  15. eo.Height = 100;
  16. eo.Margin = 2;
  17. BarcodeWriter bw = new BarcodeWriter();
  18. bw.Options = eo;
  19. bw.Format = BarcodeFormat.CODE_128;
  20. Bitmap bm = bw.Write(context.Request["barcode"] is object ? context.Request["barcode"].ToString() : "12345678901");
  21. //bm.Save(context.Server.MapPath("barcode.jpg"), ImageFormat.Jpeg);
  22. HttpResponse Response = context.Response;
  23. Response.ClearContent();
  24. Response.ContentType = "image/jpeg";
  25. bm.Save(Response.OutputStream, ImageFormat.Jpeg);
  26. bm.Dispose();
  27. }
  28. public bool IsReusable
  29. {
  30. get
  31. {
  32. return false;
  33. }
  34. }
  35. }