I am using the below mentioned code in rendering font inside of an image using handlers. It is coming as expected in development environment. But when I deploy the same in the production the boldness is increased and the text is not good. Any help is appreciated.
string imageFilePathNew = "";
string firstText = name;
PointF firstLocation = new PointF(3f, 20f);
string imageFilePath = Server.MapPath("~/mypath/" + file + ".png");
imageFilePathNew = Server.MapPath("~/mypathnew/" + file + name + ".png");
Bitmap bitmap = (Bitmap)Image.FromFile(imageFilePath);//load the image file
var format = new StringFormat
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
};
using (Graphics graphics = Graphics.FromImage(bitmap))
{
Font arialFont = new Font("Smallest Pixel-7",3);
SizeF s = TextRenderer.MeasureText(firstText, arialFont);
RectangleF rectF1 = new RectangleF(1, 8, 46, 30);
float fontScale = Math.Max(s.Width / rectF1.Width, s.Height / rectF1.Height);
using (Font font = new Font(arialFont.FontFamily, arialFont.SizeInPoints / fontScale, GraphicsUnit.Point))
{
graphics.DrawString(firstText, font, Brushes.White, rectF1, format);
}
}
//using (Graphics graphics = Graphics.FromImage(bitmap))
//{
// using (Font arialFont = new Font("Smallest Pixel-7", 10))
// {
// RectangleF rectF1 = new RectangleF(8, 17, 32, 30);
// graphics.DrawString(firstText, arialFont, Brushes.Black, rectF1,format);
// }
//}
Bitmap newbmp = new Bitmap(bitmap);
//bitmap.Dispose();
//newbmp.Save(imageFilePathNew,System.Drawing.Imaging.ImageFormat.Png);//save the image file
using (MemoryStream memory = new MemoryStream())
{
using (FileStream fs = new FileStream(imageFilePathNew, FileMode.Create, FileAccess.ReadWrite))
{
newbmp.Save(memory, ImageFormat.Png);
byte[] bytes = memory.ToArray();
fs.Write(bytes, 0, bytes.Length);
}
}
return imageFilePathNew;