I am trying to save the text as Image with font Cookie but When i convert that text with font i does not effect there as need. Please have a look into code and suggest the possible solution. Thanks in Advance
string text = "Signature sting to convert";
Bitmap bitmap = new Bitmap(1, 1);
FontFamily myFontFamily = new FontFamily("cookie");
Font font = new Font(myFontFamily, 25, 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("~/images/") + fileName, ImageFormat.Jpeg);
imgText.ImageUrl = "~/images/" + fileName;
imgText.Visible = true;
The exception I am getting from below line
FontFamily myFontFamily = new FontFamily("cookie");
Font 'cookie' cannot be found.
Please suggest how to use that font in this case.
I'm presuming you need the font, download it:
http://www.1001freefonts.com/cookie.font,
Double click on the cookie.zip file, then drag the file:
Cookie-Regular.ttf
and drop on the desktop.
Double click that and then the (windows-7) viewer will display the fonts.
Up top is an install button, click that.
The viewer will install the font to the windows font folder.
I use windows 7 for C# programming in Visual studio 2015 and the bitmap was saved after the font was installed.