【发布时间】:2012-09-08 05:34:39
【问题描述】:
我正在研究 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");
}
看看这个
static void Main(string[] 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);
}
}
【问题讨论】:
-
如果您要发布问题,请花点时间使其可读。不要在标题中添加不必要的标签,注意拼写。
标签: c# asp.net-mvc model-view-controller asp.net-mvc-2 asp.net-mvc-3-areas