Introduction:

I am working with my local website which displays local contents in local language.

Problem:

Unfortunately my local language not supported by the Google Ads as per:

enter image description here

So one way I thought was to convert all text/string into image and display images instead.(Server Side)

Question

I am using c# method to convert text to image. I dont understand its implementation for multi-line text?

Or is there a better way to support languages that ad sense doesn't support without images?

C# Code

            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";

If someone have any idea about this type of problem or any refrence/link, please do help. Thanks for your time.

Related posts

Recent Viewed