今天在BBS上看到zswang發了一個用字符串生成字符的好動動,把它改造成一個方法放在這裡,大家可以嘗試一下,應該很好玩
效果如下
。。。。。接。。。接。。。。。。
。。。。。接。。。接。。。。。。
。。。。接。。。。。接。。。。。
。。。。接。。。。。接。。。。。
。。。接。。。。。。。接。。。。
。。接。接接接接接接接。接。。。
。。。。。。接。。。接。。。。。
。。。。。。接。。。接。。。。。
。。。。。接。。。。接。。。。。
。。。。接。。。。。接。。。。。
。。接接。。。接接接。。。。。。
。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。
代碼如下
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350833.gif)
private string GetSpecialText(string CharText,string BackText,string ForeText)
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350854.gif)
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350932.gif)
...{
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
if (CharText.Length <= 0 || BackText.Length <= 0 || ForeText.Length <= 0) return "";
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
Graphics vGraphics = CreateGraphics();
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
SizeF vSizeF = vGraphics.MeasureString(CharText, Font);
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
vGraphics.Dispose();
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
Bitmap vBitmap = new Bitmap((int)vSizeF.Width, (int)vSizeF.Height);
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
vGraphics = Graphics.FromImage(vBitmap);
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
RectangleF vRectangleF = new RectangleF(0, 0, vBitmap.Width, vBitmap.Height);
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
StringFormat vStringFormat = new StringFormat();
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
vGraphics.DrawString(CharText, Font, Brushes.Black, 0, 0);
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
vGraphics.Dispose();
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
StringBuilder vBuffer = new StringBuilder();
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
for (int i = 0; i < vBitmap.Height; i++)
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350945.gif)
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311351067.gif)
...{
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
for (int j = 0; j < vBitmap.Width; j++)
...{
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
Color vColor = vBitmap.GetPixel(j, i);
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
if (vColor.ToArgb() != 0)
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
vBuffer.Append(ForeText);
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
else vBuffer.Append(BackText);
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311351022.gif)
}
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
vBuffer.AppendLine();
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311351022.gif)
}
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311350904.gif)
return vBuffer.ToString ();
![](https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017011311351086.gif)
}