我正在研究 MVC 3。问题是如果字符串的长度超过 10,我想打破字符串。来自数据库的字符串值作为用户名。我想在图像上应用该字符串.. 示例
public Image (string Name)
{
}
那么如果名称字符串超过 10 个字符,如何打破它?
public FileResult image(string image)
{
Bitmap bitMapImage = new Bitmap(Server.MapPath("/Content/themes/base/images/photo.png"));
// Bitmap bitMapImage = new Bitmap("/Content/themes/base/images/del02s(1).jpg");
//TODO : comment for revert the cation of no photo
Graphics graphicImage = Graphics.FromImage(bitMapImage);
graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
int count = image.Length;
string[] arr4 = new string[count];
if (image.Length > 9)
{
string imges = image
}
graphicImage.DrawString(image, new Font("Trebuchet MS,Trebuchet,Arial,sans-serif", 10, FontStyle.Bold), SystemBrushes.WindowFrame, new Point(15, 5));
graphicImage.DrawArc(new Pen(Color.Red, 3), 90, 235, 150, 50, 0, 360);
MemoryStream str = new MemoryStream();
bitMapImage.Save(str, ImageFormat.Png);
return File(str.ToArray(), "image/png");
}
看一下这个
静态无效主要(字符串[] args){
string image = "1234567890abcdefghijklmnopqrsy";
int count = image.Length;
if (image.Length > 9)
{
//getting Error
string img1 = image.Substring(0, 10);
string img2 = image.Substring(10, count);//getting Error Index and length //must refer to a location within the string.
//Parameter name: length"
string imge3 = img1 + "\n";
string img4 = imge3 + img2;
Console.WriteLine(img4);
}
}