c# - Antialiased text is not antialiased and Cleartype text is very ugly in windows forms -
i have following c# code graphics bitmap on windows 7 64-bit
protected graphics getimagegraphics() { var g = graphics.fromimage(image); g.smoothingmode = smoothingmode.highquality; g.interpolationmode = interpolationmode.highqualitybicubic; g.textrenderinghint = system.drawing.text.textrenderinghint.cleartypegridfit; g.fillrectangle(backbrush, new rectangle(point.empty, bounds.size)); return g; } this used follows:
protected override void redraw() { var g = getimagegraphics(); var path = roundedrectanglepath(shaperect, cornerradius); g.fillpath(selected ? selectedbrush : brush, path); g.drawpath(pen, path); foreach(var pin in pins) pin.value.render(g); var labelmax = shaperect; labelmax.inflate(-10, -10); var fmt = textformatflags.horizontalcenter | textformatflags.verticalcenter | textformatflags.wordbreak | textformatflags.wordellipsis; textrenderer.drawtext(g, task.symbol.label, font, labelmax, color.black, fmt); fmt = textformatflags.left | textformatflags.top | textformatflags.singleline | textformatflags.wordellipsis; textrenderer.drawtext(g, task.taskid, font, idrect, color.black, fmt); } the image created copied screen using:
g.drawimageunscaled(image, bounds); the resulting text ugly. rendered in solid black each pixel has been replaced 3 adjacent horizontal pixels (like old dot-matrix printer bold font)
if change textrenderinghint antialias or antialiasgridfit font rendered more without antialiasing (like singlebitperpixel)
what doing wrong?
the solution two-fold. hans pointed out, text not antialias transparent. other part of answer not use textrenderer on in-memory bitmaps described here https://stackoverflow.com/a/1578056/429328
Comments
Post a Comment