日期:2014-05-18  浏览次数:20457 次

请教类代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Web;
using System.Configuration;
using System.IO;
using System.Text;
namespace CqyCommon
{
  public abstract class commonclass
  {
  public static string GetClientIP()
  {
  string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  if (null == result || result == String.Empty)
  {
  result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
  }
  if (null == result || result == String.Empty)
  {
  result = HttpContext.Current.Request.UserHostAddress;
  }
  return result;

  }
  public static byte[] getCodeImage(string code, int p_h)
  {
  code = getCodeText(code);
  int p_w = code.Length;
  p_h = p_h + 20;
  Bitmap myBitmap = new Bitmap(p_w, p_h);
  Graphics myGrap = Graphics.FromImage(myBitmap);
  myGrap.Clear(Color.White);
  for (int i = 0; i < p_w; i++)
  {
  Pen myPen = new Pen(Color.White, 1);
  if (code.Substring(i, 1) == "|")
  {
  myPen.Color = Color.Black;
  }
  // myGrap.DrawString(_code.Substring(i, 1), new Font("宋体", 12), new SolidBrush(Color.Black), i*13, 20);
  myGrap.DrawLine(myPen, i, 0, i, p_h);
  }
  myGrap.DrawString(code, new Font("Courier New", 10), new SolidBrush(Color.Black), -4, p_h);
  MemoryStream ms = new MemoryStream();
  myBitmap.Save(ms, ImageFormat.Jpeg);
  byte[] myImage = null;
  myImage = ms.GetBuffer();
  return myImage;
  }
  public static string getCodeText(string n)
  {
  string zf = n.ToLower();
  zf = zf.Replace("0", "_|_|__||_||_|");
  zf = zf.Replace("1", "_||_|__|_|_||");
  zf = zf.Replace("2", "_|_||__|_|_||");
  zf = zf.Replace("3", "_||_||__|_|_|");
  zf = zf.Replace("4", "_|_|__||_|_||");
  zf = zf.Replace("5", "_||_|__||_|_|");
  zf = zf.Replace("7", "_|_|__|_||_||");
  zf = zf.Replace("6", "_|_||__||_|_|");
  zf = zf.Replace("8", "_||_|__|_||_|");
  zf = zf.Replace("9", "_|_||__|_||_|");
  zf = zf.Replace("a", "_||_|_|__|_||");
  zf = zf.Replace("b", "_|_||_|__|_||");
  zf = zf.Replace("c", "_||_||_|__|_|");
  zf = zf.Replace("d", "_|_|_||__|_||");
  zf = zf.Replace("e", "_||_|_||__|_|");
  zf = zf.Replace("f", "_|_||_||__|_|");
  zf = zf.Replace("g"