GDI Antialiasing does not work well on server 2008

I use System.Drawing to create some on-the-fly images that include the base image plus some stretched / scaled text. Everything is fine and neat in my LOCALHOST environment, but when I publish on my server (Server 2008), I lose some anti-aliasing and the image quality becomes grainy.

Here is an example copied from my local environment (Windows 7) and then from my server (Server 2008)

Windows 7:

enter image description here

Windows 2008:

enter image description here

As you can see, the images are the same size and the fonts are scaled the same way. The server version does not seem to have anti-aliasing to smooth the edges. Here is the main code snippet: imgSign and grSign are the installed Image and Graphics object with the given background size / color on which you want to scale / draw the text.

'Requested size of test Dim textSize As SizeF = grSign.MeasureString(textString, font) Dim intTextWidth As Integer = textSize.Width Dim intTextHeight As Integer = textSize.Height 'Create image to hold text Dim img As Drawing.Image = New Bitmap(intTextWidth, intTextHeight) Dim gr As Graphics = Graphics.FromImage(img) 'Smoothing mode gr.SmoothingMode = Drawing2D.SmoothingMode.HighQuality gr.TextRenderingHint = Text.TextRenderingHint.AntiAlias 'Scale Text Dim sngScaleWidth As Single = imgSign.Width / intTextWidth If sngScaleWidth > 1 Then sngScaleWidth = 1 'Don't scale down width if it doesn't need to be Dim sngScaleHeight As Single = imgSign.Height / intTextHeight grSign.ScaleTransform(sngScaleWidth, sngScaleHeight) 'Draw text gr.DrawString(textString, font, Brushes.White, 0, 0) 

Is there some kind of functionality that is not on server 2008 that I have to get around, or a switch that I can set to improve quality, or do I need to look elsewhere?

+2
source share
1 answer

Try also setting these settings on your gr chart.

 gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; 

to archive the best quality and double check that the fonts you use are the same on both systems.

+2
source

Source: https://habr.com/ru/post/958386/


All Articles