c# - Text is blurred when transformed in WPF -
i'm using drawingcontext.drawtext
, drawingcontext.pushtransfrom
create rotated text on visual layer in wpf see in image below, rotated text rather blurry in areas of image..
is there option can use improve this? arial font used text.
public class beamtextdrawing : frameworkelement { private readonly visualcollection _visuals; public beamtextdrawing(double scale) { if (scale <= 0) { scale = 1; } var typeface = settings.beamtexttypeface; var cultureinfo = settings.cultureinfo; var flowdirection = settings.flowdirection; var textsize = settings.beamtextsize / scale; var beamtextcolor = settings.inplanbeamtextcolor; _visuals = new visualcollection(this); foreach (var beam in building.beamsintheelevation) { var drawingvisual = new drawingvisual(); using (var dc = drawingvisual.renderopen()) { var text = convert.tostring(beam.section.id); //text = scale.tostring(); var ft = new formattedtext(text, cultureinfo, flowdirection, typeface, textsize, beamtextcolor) { textalignment = textalignment.center }; var x1 = beam.connectivityline.i.x; var y1 = beam.connectivityline.i.y; var x2 = beam.connectivityline.j.x; var y2 = beam.connectivityline.j.y; var v1 = new point(x2, y2) - new point(x1, y1); var v2 = new vector(1, 0); var hwidth = textsize; var l = geometrics.getoffset(x1, y1, x2, y2, hwidth + 5/scale); var angle = vector.anglebetween(v1, v2); var x = 0.5 * (l.x1 + l.x2); var y = 0.5 * (l.y1 + l.y2); var r = new rotatetransform(angle, x, selectablemodel.flipyaxis(y)); dc.pushtransform(r); dc.drawtext(ft, selectablemodel.flipyaxis(x, y)); } _visuals.add(drawingvisual); } } protected override visual getvisualchild(int index) { return _visuals[index]; } protected override int visualchildrencount { { return _visuals.count; } } }
update:
here image after using code:
textoptions.settextformattingmode(this, textformattingmode.display);
i'm still getting blurry results. @ middle beam text @ lower part of image.
check out article - pixel snapping in wpf applications
since wpf uses device independent pixels can create irregular edge rendering due anti-aliasing when undergoes transformation. pixel snapping means suppress these visual artifacts applying small offsets geometry of visual align geometry device pixels.
setting snapstodevicepixels
property "true" ui elements should able fix issue.
Comments
Post a Comment