Automatically choose appropriate gray color for a given background color - user-interface

I have a table in which the cells may contain normal and grayed-out text. The color for normal text is chosen dynamically according to this post in order to take account that the table's background color is theme-dependent. Now I'm wondering if there's any good way to determine an appropriate "gray" color based on the table's background, so that:
the "gray" is "really" gray when the background color is white or black
the grayed-out text is readable with all possible background colors
if possible, the grayed-out text should be distinguishable from normal text, and ideally look "paler", in the same way that gray is paler than black
Note: Other styles, such as strike-out, are not appropriate in my case, since the gray color is used to convey the idea of a table cell being "less important" than others, rather than being obsolete/unavailable/etc.

Well, your linked question selects only one of two text colors: it will be either black or white.
Did you try to just use a "dark gray" when the text color is black, and a light gray when the text color is white?

Related

Detecting anti-aliased or undersampled text image

I have an image that is essentially a text document (black and white) but due to anti-aliasing/undersampling applied during scanning, the image contains a lot of color, light tone pixels and is thus saved as a full-color image i.e: takes a lot of space.
My goal is to be able to detect Black and White image candidates in order to convert them from full color to B&W which dramatically reduces their size.
Is there a way to detect such anti-aliased/undersampled images? Doing color pixel analysis doesn't help because the colored pixels end up being close in amount to the black pixels... Essentially I want to be able to detect that the colored pixels come from anti-aliasing/undersampling a black & white image and not from a picture type image.
Here is an example image:
As you can see there are many more colors than just black. However this image is a good candidate for Black & White / Greyscale conversion instead of full color. How can I detect such images? Please note that in this example the colors tend to be on the grey side but there are many cases where they are cyan or brown etc.
I think it is a valid question. I don't have 50 reputation to post a comment so I will post this as an answer.
Basically, in a black and white anti-aliased image the various grey colors are opacity differences of the black color. If we observe those pixels they will be like these listed below. So, if the operation is a color manipulation then apply the same opacity picked up from those grey pixels to the new color.
rgba(0,0,0,0.6)
rgba(0,0,0,0.9)
rgba(0,0,0,0.5)
rgba(0,0,0,0.9)
rgba(0,0,0,0.6)
rgba(0,0,0,0.1)
rgba(0,0,0,0.5)
In my opinion, the pixels other than grey, in this example image, cyan and brown as it appears can be safely ignored because they seemed like not part of the original text. If there were a few more example images of non grey pixels would have been good. But if we cannot ignore them just need to get the pixel opacity and apply the same color manipulation. In other words we treat them as black pixels.

Ghostscript true black and white conversion

I'm trying to convert a colour pdf to a pure black and white tiff i.e. if the colour is anything other than white I want it to be pure black. At the moment I have colour lines turning speckled and faint which I believe is due to half-toning. Is there a way I can overwrite this half-toning? Examples below.
Current Output:
Desired Output:
Thanks.
Shades of gray are halftoned, if you want to avoid that you need to decide on a threshold below which gray values are white, and above which gray values are black.
Then you set a transfer function that maps the values. Note that its possible for both PDF and PostScritp files to include their own transfer functions (though its rare) and these may override your own.

Setting the background to transparent using GIMP

Using GIMP 2, I have an image of a grey chair on a white background, as below:
I now want to set the background to transparent. Therefore, I decided to use GIMP's "Color To Alpha" tool. So, I told it to set all pixels which are white (255, 255, 255) to transparent, as below:
This did set all white pixels to transparent. However, it also set the grey pixels on the chair to be partially transparent, as below:
So when I export this image and place it in front of a background, there is no white box around the chair -- but the background partially shows through the chair.
What am I doing wrong?
First, this question is offtopic here, and should be on https://graphicdesign.stackexchange.com .
Second, it is trivial enough just to answer: the color to alpha plug-in is not there to turn a single color, as seem on the image, to transparency: it is a sophisticated plug-in that will remove one color of your image in a way that, if you lace the new image over a background of the same color the color you removed, you get the original image back.
Thus, in your case, it removed the "whiteness" of your chair, transforming all pixels to different opaque shades of black - so that when placed over white, you get the original image.
To simply remove the white, you have to cick on the Select By Color tool (by default th 5th icon on the toolbox), click on the white background to have it selected, and then just edit->cut. (It won't work if your image layer does not have transparency to start with - if that is the case, prior to edit->cut do Layer->Transparency->Add Alpha Channel).
If you get aliased borders, then, after edit>cut, but prior to dismissing your selection, you can do Select->Border... by 1 or 2px, and then use the color to alpha filter with White on this selection.
For more information on Color to Alpha, I have this other answer its use and comparison with edit-cut here: https://graphicdesign.stackexchange.com/questions/28058/gimp-color-to-alpha-is-not-selectable/28097#28097
Just use a selection to restrict the action of Color to alpha where it matters: backgroundand edge pixels:
Select background with fuzzy select
Select>Grow by one pixel so that the selection ofverlaps the edge pixels
Color>Color to alpha

What system color should be used to draw text on accent background?

I need to put text in a panel with accent (PhoneAccentBrush) background. PhoneForegroundBrush for text looks good in dark theme, but doesn't play well with light theme. It looks like the text always should be white regardless the theme.
What color should be used in such cases?
White is probably your best bet. (It's used for the text on live tiles to aid easier readability regardless of the tile color-which is often the accent color.)
You could also consider black.
The size of the panel and the weight & size of the text will impact appropriateness of color choice too.

How does one reproduce the inset text style when drawing text with Mac OS X Cocoa?

I'm talking about the groove style of the text on focussed title bars, or safari's bookmarks bar for example. Is there an easy way to reproduce this style when using:
[string drawAtPoint:... withAttributes:...];
If you want it to look perfect, you'll need to draw the text twice.
As you can see when zooming in on labels below toolbar items in any app, or for instance the bookmarks bar in Safari (Control+scroll up, control+option+\ to toggle smoothing of the zoomed in image), the text is rendered with sub-pixel anti-aliasing, at least when "Font smoothing style:" in the "Appearance" system preferences is set to medium, which it will be by default on Macs with a built-in or external Apple flat-panel display.
NSShadow can not be used with sub-pixel anti-aliasing, so if you simply set an NSShadowAttributeName in the attributes dictionary you're drawing your string with, you will notice sub-pixel anti-aliasing is MIA when you zoom in on your rendered text.  Due to the way NSShadow is designed, no matter what color you set your NSShadow instance to —even if it is opaque— it will always be drawn with an alpha channel, making sub-pixel antialiasing impossible.
The solution is really very simple:
Draw your text once with a white color with some transparancy,
Then draw it once more on top of that, a pixel higher in a shade of grey of your liking with no transparancy.
Your 'shadow' will draw without sub-pixel antialiasing, but the actual text on top op of it will draw with it, giving you the exact same effect as standard Cocoa toolbar button item labels, or items in the Safari bookmarks bar.
EDIT: It seems that Safari's bookmarks bar items draw their 'shadows' with sub-pixel accuracy as well, so the way they did it is probably by choosing an opaque shade of gray for the white 'shadow' text as well; drawback of that approach: you are tying your drawing code to only work well on a particular background color, e.g. if your elements will be used on a blue background, you'll want to set that color to a light shade of blue, to appear like it's semi-transparent white.
Draw it with an un-shadow below it. Use a shadow with color white, opacity 50% or so, blur 0, offset 1 pt down.
A simple way to do this is to simply draw the text twice. The first time, you draw it 1 pt lower, in white, at 50% opacity. The second time, you draw it in the desired position, in the desired color, at the desired (probably 100%) opacity.

Resources