GDI Antialiasing not working well on Server 2008

给你一囗甜甜゛ 提交于 2019-12-22 17:46:10

问题


I'm using System.Drawing to generate some images on the fly that include a base image plus some stretched / scaled text. Everything is nice and neat on my LOCALHOST environment, but when I publish to my server (Server 2008), I lose some of the antialiasing and the image quality gets grainy.

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

Windows 7:

Windows 2008:

As you can see, the images are the same size, and the fonts are scaled the same as well. The Server version doesn't seem to have anti-aliasing to smooth out the edges. Here's the main piece of code: imgSign and grSign are an established Image and Graphics object with a set size / background color onto which the text is to be scaled / drawn.

'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 functionality that isn't there on Server 2008 that I have to work around, or a switch I can set to increase the quality, or do I need to look elsewhere?


回答1:


Try also to set on your Graphics gr this settings

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

to archive better quality, and double check that the fonts that you are using is the same on both systems.



来源:https://stackoverflow.com/questions/13144466/gdi-antialiasing-not-working-well-on-server-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!