-
-
Notifications
You must be signed in to change notification settings - Fork 852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drawing crisp single pixel width text #138
Comments
don't use a pen instead use a brush or color try var top = height - 4;
var font = new Font(FontCollection.SystemFonts.Find("Arial"), 10f, FontStyle.Regular);
var brush = new SolidBrush(Color.Black);
img.DrawText(orderTicket.Code, font, brush, new System.Numerics.Vector2(50, top), new TextGraphicsOptions(false)); Basically the rule of thumb is a |
BTW its awesome to see this usage of it the library. 👍 |
The Font library doesn't currently perform pixel grid aligning which should help knock the glyphs over to better match the pixel layout. I've added an issue over there to track that. SixLabors/Fonts#19 pixel grid aligning should be part of the problem. Additionally I've never tested trying to get a font to render at a single pixel width, i'll have to have a play to see if there anything quick I can do to improve the renderer for you. You could try seeing if offsetting the text by half a pixel helps i.e. draw the text at I'll have a play around with trying to draw the text at this size and see if I can make it "just work" for you. |
I tried the manual offset alignment but it only helped a tiny amount If i would have to fix it like this i would have to align each and every single letter\number... 😢 https://en.wikipedia.org/wiki/ClearType that is the word that really describes this problem |
@KLuuKer try "1.0.0-alpha4-00021" or higher for both ImageSharp & ImageSharp.Drawing. Its still not as good as System.Drawing because I'm still not doing font hinting and grid fitting but it should improve general font rendering making small glyphs render better. You will want to render using anti-aliasing for the closest match. |
@tocsoft o wow this is so much better now, thank you very much for the quick (and huge) improvement in the rendering even with aa turned off it also looks better then before thank you very much for doing this, i can finally start setting fire to net461 😄 (it's a big app so it might take some time to burn) |
Great work @tocsoft ! 💯 |
@KLuuKer All the same, it still doesn't reproduce that pixel-perfect aligned text produced by System.Drawing, does it? I totally know what you mean by that, it makes Arial look just perfect. @tocsoft Was this ever fixed with ImageSharp? I've been experimenting with the latest (1.0.0-beta15) and as this issue above says, antialiased looks alright (though not the same as the "pixel perfect" look; possibly a bit too fuzzy), and unantialiased is atrocious: |
Try the latest Fonts library MyGet build with hinting enabled. I’ve just done a ton of work there. P.S ClearType contains a bunch of hacks to make old fonts like Arial look good at low resolution. Other font layout libraries like FreeType have opted not to include those hacks as they add massive development complexity at the cost of performance. We’ve opted to do the same. P.P.S We don’t use the word atrocious here. It’s not nice to be negative. |
Wasn't intended as a negative, more as a factual description of how difficult it is to actually read. :-) Sorry, I don't know what you mean by the MyGet? |
MyGet is where we host our nightly builds. https://github.com/SixLabors/Fonts#installation |
Hey @jez9999, have you found a good configuration to make it render as good as possible? I've tried lots of different fonts (including "pixel-like" fonts), playing with the Brushes/Pens and Hinting. Probably a me-problem but I couldn't manage to play with aliasing's options. I couldn't get something clearer than this: If you zoom it you can see different shade of black: My wish would be to limit that amount of shade, even if it lowers the general quality, but I couldn't manage to get something better than this. It is an issue to me right now because I have something that then attempts to replace the color around the text (sadly without any tolerance) which then makes the final rendering a bit weird. |
What do you mean by this? Are you using the 1.0.0-beta19. The hinter has been fixed and works the same as Freetype's one now.
That's more an issue than the font rendering IMO. You always need tolerance when doing color replacement. ImageSharp.Drawing has a Though of course the smart thing to do would be to draw the text onto the correct colored background in the first place. |
@AnastasiiaShta This is a closed issue. Please open a new discussion or issue in the correct repository with the relevant details. |
I'm new here, sorry. |
Prerequisites
DEBUG
andRELEASE
modeDescription
With the old System.Drawing i am using ZXing.Net to make it render a image like this
i tried allot of varations with the following (enable\disable AA, font sizes, pen width's, even dpi)
but i cant get that nice crispy single pixel wide text (no need to concern yourself with the barcode that works just fine)
maybe @tocsoft can help with this
System Configuration
The text was updated successfully, but these errors were encountered: