简介
我正在使用当地网站显示本地语言的本地网站。
问题:
不幸的是,Google广告不支持我的本地语言:
所以我想的一种方法是将所有文本/字符串转换为图像并显示图像。(服务器端)
问题
我使用c#方法将文本转换为图像。我不理解多行文字的实现?
或者,有没有更好的方法来支持广告感不支持没有图像的语言?
C#代码
string text = str.Trim();
Bitmap bitmap = new Bitmap(1, 1);
Font font = new Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Pixel);
Graphics graphics = Graphics.FromImage(bitmap);
int width = (int)graphics.MeasureString(text, font).Width;
int height = (int)graphics.MeasureString(text, font).Height;
bitmap = new Bitmap(bitmap, new Size(width, height));
graphics = Graphics.FromImage(bitmap);
graphics.Clear(Color.White);
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
graphics.DrawString(text, font, new SolidBrush(Color.FromArgb(255, 0, 0)), 0, 0);
graphics.Flush();
graphics.Dispose();
string fileName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".jpg";
bitmap.Save(Server.MapPath("~/App_Images/") +"11"+fileName, ImageFormat.Jpeg);
//imgText.ImageUrl = "~/images/" + fileName;
//imgText.Visible = true;
return "~/App_Images/My_Converted.jpg";
如果有人对此类问题或任何参考/链接有任何疑问,请提供帮助。谢谢你的时间。
答案 0 :(得分:1)
在C#中,您只需在字符串中添加换行符(\ r \ n)即可。
我将您的问题编辑为更具吸引力且与更广泛的受众群体相关。请暂时留下这个问题没有标记,听一些更多的想法,欢呼!