Text effect to enhance readability of small fonts - c#

In a view I have a smaller font, foreground is white and background is dark grey.
At the moment I use a drop shadow effect like
<DropShadowEffect BlurRadius="0"
Opacity="0.99"
ShadowDepth="1"
Direction="270"
Color="Black"
This looks zoomed as this:
It works good on bigger fontsizes, but not very good on small scales as can be seen here:
What would be a good text effect to enhance overall readability?
I found this question which uses an outer stroke around the text,
but it does not work at all on smaller fontsizes.

For completeness:
As#sa_ddam213 said use TextFormattingMode.
Furthermore you can experiment with the Anti-Aliasing algorithms via TextRenderingMode.
If you use ClearType, you can additionally experiment with ClearTypeHint.
Alternatives are use larger text or a font specially designed for small sizes like a pixel font.

Related

How to avoid "adding up" of opacities in SkiaSharp

I'm currently creating a Xamarin.Forms app. One of my pages uses SkiaSharp to allow users to highlight parts of an image in a text marker style (i.e. a yellow brush with low opacity).
This is how the related SKPaint object is defined:
var strokePaint = new SKPaint()
{
Color = Color.FromRgba(255, 255, 0, 100).ToSKColor(),
Style = SKPaintStyle.Stroke,
StrokeWidth = StrokeWidth
};
That's working fine so far, but what bothers me is that the opacity "increases" when I have multiple overlapping paths, until at some point the underlying picture isn't visible anymore.
What could I do to avoid this overlapping? I was thinking about merging all paths into one, but that doesn't seem to work because the user is allowed to change StrokeWidth in between strokes and I didn't see any way of drawing paths with varying width.
I hope any of you guys has some help for me. Any idea is appreciated!
I'm not super familiar with Skia, but I took a look at the documentation for SKPaint, and it looks like it has a BlendMode property. Based on how similar things work in other systems, that should control how colors are combined. You might have to try different values to get the effect you are looking for. Dst, or Modulate look like good candidates. – Bradley Uffner
Thanks for your answer Bradley! I went with the Darken blend mode and set opacity to 255, which creates a very nice effect when highlighting text (only the darker color is visible, so dark text on a light background becomes dark text on a background of my marker color).

Image processing - Reduce object thickness without removing

I have an image like below.
What I want is a monochrome image such that white parts are kept white, the rest is black. However, the tricky part is that I also want to reduce the white parts to be one pixel in thickness.
It's the second part that I'm stuck with.
My first thought was to do a simple threshold, then use a sort of "Game of Life" type iterative process where a white pixel was removed if it had neighbours on one side but not the other (i.e. it's an edge) however I have a feeling this would reduce ends of lines to nothing over time so I'd end up with a blank image.
What algorithm can I use to get the image I want, given the original image?
(My language of choice is C#, but anything is fine)
Original Image:
After detecting the morphological extended maxima of a given height:
and then thinning gives:
You can also manipulate the height parameter, or prune the thinned image.
Code in Mathematica:
img = ColorConvert[Import["http://i.stack.imgur.com/zPtl6.png"], "Grayscale"];
max = MaxDetect[img, .55]
Thinning[max]
EDIT I followed my own advice and a height of .4 gives segments which are more precisely localized:
I suggest that you look into Binary Morphological transformations such as Erosion and Dilation. Graphics libraries such as OpenCV() http://opencv.willowgarage.com/wiki/ and that statistical/matrix tool Gnu Octave http://octave.sourceforge.net/image/function/bwmorph.html support these operations.

Image rescale (downsize) with Silverlight

I have an array of graphs, that are 2000x1000 pixels pngs. When I put them into a silverlight Image that auto-sized with the browser window, DisplayImage.Source = new BitmapImage(GetHeatmapURL()); they images look distorted and for some browser sizes much worse than for some others.
I want to fiddle with some setting that would improve the quality of this downsampling, is this possible? Am I doing something wrong? My first approach was to put the Image into a Viewbox. That looked even worse. Googling gives virtually nothing useful...
Any help much appreciated.
PS. I'm working with Silverlight 4.
You could check out the WriteableBitmapEx project on CodePlex which gives you a Resize() extension method for the Silverlight WritableBitmap class where you can use either Bilinear or Nearest Neighbor interpolation. Resizing with the Bilinear interpolation might give you something that looks better than the ViewBox resizing, but you would have to test it out.
var resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
When making use of the Viewbox you need to make sure to set Stretch to Uniform to respect the original height/width ratio.
In regards to the rendering of the image at the given aspect ratio and size; that is contingent on the framework.

Question about "Additive blending" and "Hue replacement"

Since drawing fonts is quite expensive in terms of CPU,
many developers use a rasterized font to draw text on video games; that's what I did too.
Using additive blending when drawing the text works fine regarding glyph edges,
these merge nicely with the background color.
But it brought another issue,
I decided to implement a 'color' parameter for drawing the font, instead of producing glyphs bitmaps for each color, otherwise memory usage might be an issue soon; depending how many glyphs and colors are needed but also the font size and since it supports Unicode, there can be thousands of glyphs needed depending the language.
Now when I blend, say a 'Green' font on a 'Red' background, it goes 'Orange' !
Which is the purpose of additive blending, but trying to bypass this went a little more complicate than expected. Obviously it doesn't happen when background is 'Black' but it might not be that color in the end.
How can I recolor my 'White' font to 'Any' color, while still retaining additive blending over 'Any' color ?
Thanks a lot :D
I have fixed it, here's the answer !

Creating high resolution image

I have an image (png) with resolution 1600*1200 (96 dpi).
I have put some text on the image and then saved it to a file for it to be loaded using silverlight's deepzoom with the pivotviewer. The text is blurry when zooming in and I was wondering how I can make the text look sharper (only if zooming in a bit).
This is my first bit of programming with images/graphics, so any info would be great (i.e. links to read, concepts to understand etc)
JD.
I've never used these controls before, but you might end up having to override the zooming algorithm (if that's even possible, I don't know). If you have text in an image and you're not using vector-based images (SVG, EMF, WMF, etc.), any sort of stretching is going to be blurry.
A different zooming algorithm, if it's a possibility, can decide how to stretch the pixels. For text, you're looking for something called "Nearest Neighbor" or maybe even "Bi-cubic" interpolation while the image is resizing. These methods are more expensive in terms of processing, so you might not get as smooth of a zoom as with the default interpolation algorithm (whatever it is).
There are some forum posts that start the same discussion, but with no real direction. Maybe you can follow them and see how they progress. I'm afraid I can't be of much help otherwise.
http://social.expression.microsoft.com/Forums/en-US/deepzoomcomposer/thread/dee528a2-06ae-4426-b096-5baafec499ff
http://weblogs.asp.net/bleroy/archive/2009/12/10/resizing-images-from-the-server-using-wpf-wic-instead-of-gdi.aspx
In the last post they refer to the different interpolation algorithms in a BitmapScalingMode enumeration. One of those options is NearestNeighbor. There are also some examples of resized images.
Update:
In this article, the author takes a look at a way to change the quality of the image tiles that the Deep Zoom control uses (and he's using Silverlight!). The author effectively changes the way images are created with a few lines of code in his project:
if (bSmoothScaling)
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
}
In that list of assignments you can find the interpolation mode I've been mentioning, as well as some other things I wasn't aware of. The author does mention a significant impact on performance with everything set to "High Quality."
Hopefully you can take the concept and incorporate it into Silverlight somehow. Good luck!

Categories