文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>c#获取部分DRAW

c#获取部分DRAW

时间:2011-05-06  来源:落冰

//获取部分
public class GF_GET
{
/// <summary>
/// 根据坐标点获取屏幕图像
/// </summary>
/// <param name="x1">左上角横坐标</param>
/// <param name="y1">左上角纵坐标</param>
/// <param name="x2">右下角横坐标</param>
/// <param name="y2">右下角纵坐标</param>
/// <returns></returns>
public static Image GetScreen(int x1, int y1, int x2, int y2)
{
int w = (x2 - x1);
int h = (y2 - y1);
Image myImage
= new Bitmap(w, h);
Graphics g
= Graphics.FromImage(myImage);
g.CopyFromScreen(
new Point(x1, y1), new Point(0, 0), new Size(w, h));
IntPtr dc1
= g.GetHdc();
g.ReleaseHdc(dc1);
return myImage;
}

/// <summary>
/// 获取指定文件的扩展名 例: .txt
/// </summary>
/// <param name="fileName">指定文件名</param>
/// <returns>扩展名</returns>
public static string GetFileExtName(string fileName)
{
if (GF_IsOk.IsStrNullOrEmpty(fileName) || fileName.IndexOf('.') <= 0)
return "";

fileName
= fileName.ToLower().Trim();


return fileName.Substring(fileName.LastIndexOf('.'), fileName.Length - fileName.LastIndexOf('.'));
}

public static string GetSubString(string p_SrcString, int p_Length, string p_TailString)
{
return GetSubString(p_SrcString, 0, p_Length, p_TailString);
}

public static string GetUnicodeSubString(string str, int len, string p_TailString)
{
string result = string.Empty;// 最终返回的结果
int byteLen = System.Text.Encoding.Default.GetByteCount(str);// 单字节字符长度
int charLen = str.Length;// 把字符平等对待时的字符串长度
int byteCount = 0;// 记录读取进度
int pos = 0;// 记录截取位置
if (byteLen > len)
{
for (int i = 0; i < charLen; i++)
{
if (Convert.ToInt32(str.ToCharArray()[i]) > 255)// 按中文字符计算加2
byteCount += 2;
else// 按英文字符计算加1
byteCount += 1;
if (byteCount > len)// 超出时只记下上一个有效位置
{
pos
= i;
break;
}
else if (byteCount == len)// 记下当前位置
{
pos
= i + 1;
break;
}
}

if (pos >= 0)
result
= str.Substring(0, pos) + p_TailString;
}
else
result
= str;

return result;
}

/// <summary>
/// 取指定长度的字符串
/// </summary>
/// <param name="p_SrcString">要检查的字符串</param>
/// <param name="p_StartIndex">起始位置</param>
/// <param name="p_Length">指定长度</param>
/// <param name="p_TailString">用于替换的字符串</param>
/// <returns>截取后的字符串</returns>
public static string GetSubString(string p_SrcString, int p_StartIndex, int p_Length, string p_TailString)
{
string myResult = p_SrcString;

Byte[] bComments
= Encoding.UTF8.GetBytes(p_SrcString);
foreach (char c in Encoding.UTF8.GetChars(bComments))
{
//当是日文或韩文时(注:中文的范围:\u4e00 - \u9fa5, 日文在\u0800 - \u4e00, 韩文为\xAC00-\xD7A3)
if ((c > '\u0800' && c < '\u4e00') || (c > '\xAC00' && c < '\xD7A3'))
{
//if (System.Text.RegularExpressions.Regex.IsMatch(p_SrcString, "[\u0800-\u4e00]+") || System.Text.RegularExpressions.Regex.IsMatch(p_SrcString, "[\xAC00-\xD7A3]+"))
//当截取的起始位置超出字段串长度时
if (p_StartIndex >= p_SrcString.Length)
return "";
else
return p_SrcString.Substring(p_StartIndex,
((p_Length
+ p_StartIndex) > p_SrcString.Length) ? (p_SrcString.Length - p_StartIndex) : p_Length);
}
}

if (p_Length >= 0)
{
byte[] bsSrcString = Encoding.Default.GetBytes(p_SrcString);

//当字符串长度大于起始位置
if (bsSrcString.Length > p_StartIndex)
{
int p_EndIndex = bsSrcString.Length;

//当要截取的长度在字符串的有效长度范围内
if (bsSrcString.Length > (p_StartIndex + p_Length))
{
p_EndIndex
= p_Length + p_StartIndex;
}
else
{
//当不在有效范围内时,只取到字符串的结尾

p_Length
= bsSrcString.Length - p_StartIndex;
p_TailString
= "";
}

int nRealLength = p_Length;
int[] anResultFlag = new int[p_Length];
byte[] bsResult = null;

int nFlag = 0;
for (int i = p_StartIndex; i < p_EndIndex; i++)
{
if (bsSrcString[i] > 127)
{
nFlag
++;
if (nFlag == 3)
nFlag
= 1;
}
else
nFlag
= 0;

anResultFlag[i]
= nFlag;
}

if ((bsSrcString[p_EndIndex - 1] > 127) && (anResultFlag[p_Length - 1] == 1))
nRealLength
= p_Length + 1;

bsResult
= new byte[nRealLength];

Array.Copy(bsSrcString, p_StartIndex, bsResult,
0, nRealLength);

myResult
= Encoding.Default.GetString(bsResult);
myResult
= myResult + p_TailString;
}
}

return myResult;
}

/// <summary>
/// 获取Email HostName 例 [email protected] 获取出来时@gmail.com
/// </summary>
/// <param name="strEmail"></param>
/// <returns></returns>
public static string GetEmailHostName(string strEmail)
{
if (strEmail.IndexOf("@") < 0)
{
return "";
}
return strEmail.Substring(strEmail.LastIndexOf("@")).ToLower();
}

/// <summary>
/// 返回URL中结尾的文件名
/// </summary>
public static string GetFilename(string url)
{
if (url == null)
{
return "";
}
string[] strs1 = url.Split(new char[] { '/' });
return strs1[strs1.Length - 1].Split(new char[] { '?' })[0];
}


/// <summary>
/// 根据阿拉伯数字返回月份的名称(可更改为某种语言)
/// </summary>
public static string[] Monthes
{
get
{
return new string[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
}
}



相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载