CGContextSetShadowWithColor and Shadow Color - objective-c

I've been searching for a way of casting inner glow (shadow) on NSImage. And I've landed on this topic. The code given under this topic looks promising. It's an unfamiliar territory for me now. Anyway, I'm stuck with the following line.
CGContextSetShadowWithColor(c,CGSizeMake(0,-1),innerShadowBlurRadius,CGColorGetConstantColor(kCGColorBlack));
More specifically, I don't quite understand the color part. According to the documentation, the last term is CGColorRef, which I have never used. I suppose it's the color type used for Quartz 2D drawing. In other words, specify a color in the language that Quartz 2D understands, maybe? Anyway, the documentation further suggests that there are three color constants. kCGColorWhite, kCGColorBlack, kCGColorClear. Does that mean I cannot specify an RGB color in this respect?
Thank you for your help.

No that's not what it means, and yes, you can specify RGB values; probably just not in the way you might be thinking. Quartz uses something known as CGColorSpaceRef, which you can think of as multidimensional — and each dimension represents a specific color component. An example would be the colors in the RGB color space, as three dimensions (red, green, and blue). The intensity of each component is represented by floating point values, and their range and meaning depends on the color space in question.
This should give you more concise information that you're looking for:
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGColorSpace/Reference/reference.html#//apple_ref/doc/uid/TP30000949
Specifically take a look at:
CGColorCreateGenericRGB
Creates a color in the Generic RGB color space.
CGColorRef CGColorCreateGenericRGB(
CGFloat red,
CGFloat green,
CGFloat blue,
CGFloat alpha
);
and also the section on Constant Colors

Related

CreateJS: how to change color of bitmap image

I'm using createJS to build some easy game.
I have an image (white fill and black stroke) and I would change the black color to another.
Is it possible?
Thanks
The three ways to do color adjustments in EaselJS are:
Composite Operations: You can draw an image using a composite operation (such as "destination-in") to determine how pixels are laid down. This is probably not going to give you the result you want. Here is an example of a black PNG being changed to different colors using compositeOperation.
Color Filters. EaselJS has both a ColorFilter and a ColorMatrixFilter, which assist with modifying colors. The first uses parameters to multiply and add to the color and alpha channels, but is a little harder to use. The second uses a ColorMatrix to adjust hue, saturation, contrast, and brightness. This may not work for you, since changing the black pixels is kind of the opposite of color filters do.
A Custom Filter. EaselJS supports custom filters (such as the Threshold Filter in the extras folder. This is probably your best option, and might take massaging to get what you need.
Hope that sheds some light.

Change a color in a UIImage

I will like to know how I can change just one color in a image.
Like saying: if the color in this pixel is "red" change it to "blue".
The technical approach is straightforward:
get all pixel values (explained here)
Look for the pixel values you don't like and change them
Draw the image using the changed pixel values (explained here)
Keep in mind, if you mix the three steps into one method, without creating UIColor objects but changing them and immediately afterwards drawing the changed image, you'll get much better performance.

Programmatically, how does hue blending work in photoshop?

In Photoshop you can set a layer's blending mode to be "Hue". If that layer is, for example, filled with blue then it seems to take the layer below and makes it all blue wherever a non-whiteish color exists.
I'm wondering what it's actually doing though. If I have a background layer with a pixel aarrggbb and the layer on top of that is set to blend mode "Hue" and there's a pixel aarrggbb on that layer, how are those two values combined to give the result that we see?
It doesn't just drop the rrggbb from the layer below. If it did that it'd color white and black as well. It also wouldn't allow color variations through.
If a background pixel is 0xff00ff00 and the corresponding hue layer pixel is 0xff0000ff then I'm assuming the end result will just be 0xff0000ff because the ff blue replaces the ff green. But, if the background pixel is 0x55112233 and the hue layer pixel is 0xff0000ff, how does it come up with the shade of blue that it comes up with?
The reason I ask is that I'd like to take various images and change the hue of the image programmatically in my app. Rather than storing 8 different versions of the same image with different colors, I'd like to store one image and color it as needed.
I've been researching a way to replicate that blending mode in javascript/canvas but I've only come up with the "colorize" filter/blend mode. (Examples below)
Colorize algorithm:
convert the colors from RGB to HSL;
change the Hue value to the wanted one (in my case 172⁰ or 0.477);
revert the update HSL to RGB
Note: this is ok on the desktop but it's noticeably slow on a smartphone, I found.
You can see the difference by comparing these three images. Original:
colorize:
Fireworks' "blend hue" algorithm (which I think is the same as Photoshop's):
The colorize filter might be a good substitute.
RGB/HSL conversion question
Hue/Chroma and HSL on Wikipedia
I found an algorithm to convert RGB to HSV here:
http://www.cs.rit.edu/~ncs/color/t_convert.html
Of course, at the bottom of that page it mentions that the Java Color object already has methods for converting between RGB and HSV, so I just used that.

How to replace a color in an image?

I'm in search of a simple algorithm to replace a color in an image with a different one like in this one->
http://en.wikipedia.org/wiki/File:Colorswaphelicon.png
I'm using VB.NET. Can a "flood fill" algorithm be applied for this purpose?
Please provide a link if possible.
Greetings.
If you need to replace a color of a connected area then flood fill may work for you. For changing the color in the whole image check How to: Use a Color Remap Table and Recoloring Images topic.
Edit:
To replace all intensities of a color shade, you can check and replace the color hue (e.g. see How To Converting Colors Between RGB and HLS (HBS)). Specifically, colors with hue and saturation within a certain range of a source color can be changed to colors with original intensity and hue and saturation of the target color.
Also, you may find helpful How to change RGB color to HSV? and HSL in .net.

changing color of monitor

i would like to program a little app that will change the colors of the screen. im not talking about the darkness. i want it to mimic what it would look like if for example you put on blue lenses or red lenses. so i would like to input the color and i want the screen to look as though i put on lenses of that particular color. well i actually need the program to semi-permanently change the users experience on the computer. i need the computer for the entire session that it is turned on to be changed this color
Transparent, Click Through forms might help you out. It makes a nice see through form that lets mouse clicks pass through it. The solution is in VS2003 format, but it upsizes to 2008 nicely. You could take that sample, rip the sliders off, get rid of the borders and make it fullscreen + topmost. I don't know if it'll accurately simulate a lens though, someone more into optics can tell me if I'm wrong :-)
If the lenses you are trying to simulate are red, green or blue, simply zeroing the other two colour components of each pixel should work. A coloured filter lens works by passing only a certain wavelength of light, and absorbing the others. Zeroing the non-desired components of the colour should simulate this accurately, I believe.
To simulate cyan, magenta, or yellow lenses, zeroing the one other colour component (e.g. the red component in the case of cyan tinted glasses) should work.
I'm not sure how to generalise beyond these simple cases. I suspect converting to say HSV and filtering based on the hue might work.
To change this for the entire system and use it in interactions with ordinary programs, you could change the colour profile for the display. For paletted/indexed-colour displays, this could be done by changing the colour look-up table (CLUT) for the display adapter. PowerStrip is a handy utility with versatile colour controls that should be able to achieve this quickly and easily on modern display adapters (e.g. by adjusting the red, green and blue response curves independently).
I came across Color Oracle and thought it might help. Here is the short description:
Color Oracle is a colorblindness simulator for Windows, Mac and Linux. It takes the guesswork out of designing for color blindness by showing you in real time what people with common color vision impairments will see.
Take a snapshot of the screen, convert each pixel into its grayscale value, then change the pixel value to a percentage of red. This will preserve the contrast throughout the image while also presenting a red tone.
To convert to grayscale in C#:
https://web.archive.org/web/20141230145627/http://bobpowell.net/grayscale.aspx
Then, to convert to a shade of red, zero out the values in the green and blue for each pixel.
(You can probably do the above in one shot, but this should get you started.)