Sprite transparency in Quartz, Objective C - objective-c

In Java I can make a background rect colored blue. I can then draw a load of sprites also with blue as the background color. I can then make it so that particular blue does not show up when drawing to the canvas or view as it is here, how do I do this in Quartz in Objective C?

You can use CGImageCreateWithMaskingColors to create a copy of an image with the blue pixels changed to transparent. This function was (according to the documentation) added in macOS 10.4 (Tiger). It is discussed in“Masking an Image with Color” in the Quartz 2D Programming Guide.

Related

Why do transparent objects lose their color when using ray-traced translucency?

When I swap from rasterized translucency to ray traced translucency, transparent objects lose their color.
Rasterized translucency
Ray traced translucency
Notice how the fourth sphere is red when using rasterized translucency, and clear when using ray traced translucency. Is this a limitation of Lumen, or should I adjust my material?
If it's a Lumen limitation, are there are recommended ways to get around this?

Creating an animation in Xcode?

I have around 100 PNGs (that I created) that I want to create an animation out of. I however created the animation in a vector graphics editor, therefore each PNG has a white background. How do I make Xcode not show the white background and instead just the image itself? I will be displaying the animation in a transparent window, so a background completely ruins the effect.
Note I'm using Xcode 3.2.6 on Snow Leopard. I'm specifically asking about a Mac application not an iOS one.
I recommend exporting your images again with a transparent background. That would save you a lot of trouble. If that's not an option, have a look at Quartz 2D Masks.

Coloring a CCSprite without only using its prime colors

I have a CCSprite that was created from a png with transparent background.
I want to be able to apply colors to this sprite in a way that I`m free to define which color it is, without the actual color of the sprite affecting the amount of each color I have to add.
I`ve tried this:
mySprite.color = ccc3(200,200,255);
In an attempt to add a little blue-ish feel to my sprite, but as it works by setting the amount of tint that's gonna be displayed based on existant color of the sprite, and my sprite has virtually no blue in any of it (most of it is yellow) the resulting effect is pretty sketchy, everything gets really dark, and there is one slight blue-ish coloring, but not as I wanted.
The ideal effect for me on this case would be to ADD a light blue mask to it with very low alpha.
Is there an easy way to do that without composing sprites?
I've tried using CCTexture2D, but had no luck, as there is no built in method for working with colors, and most tutorials only teach you how to build textures out of image files.
This is deceptively hard to do in code with the original sprite. Another option would be:
create a new sprite, which is just a white outline version of your original sprite
the color property of this white sprite will now respond exactly to the RGB values you pass in
so pass in your light blue value to the white sprite and set the opacity correctly
then overlay it on your original sprite
Any good?
The only way you can achieve this is by overlaying (masking) the sprite with the proper OpenGL blend functions. When you say "add a light blue mask" then that's what you need to do. You may find this visual blendfunc tool helpful, if only to understand how blending with mask sprites works and what you can achieve with it. There's no built-in support for this by Cocos2D however, so you'll have to revert to pure OpenGL inside a cocos2d node's -(void) draw {} method.
Tinting (changing the color property) will only modify the RGB channels of the entire image by changing the vertex colors of all 4 vertices.

Quartz 2D animating text?

i have to animate text around a circle. The text will also scale up/down. Whats the best approach to accomplish this? (i am using Quartz 2D)
My approach is:
-- Calculate point using sin and cos methods.
-- Move Pen there and draw text with alpha and size.
-- Clear the screen
-- Calculate next point using sin and cos methods.
-- Move pen there and draw text with alpha and size.
-- clear the screen
so on...
any better way?
If you're targeting iPhone OS ≥3.2, use CATextLayer.
Otherwise, you could create a UILabel and modify its transformation value, or control a CALayer directly.
If you're constrained to Core Graphics the method your described is the best already, but CG is not an animation framework. You should use Core Animations for UI animations.

How To Draw More Precise Lines using Core Graphics and CALayer

Hello I am having a hard time making this UI element look the way I want (see screenshot). Notice the image on the right--how the line width and darkness looks inconsistent compared to the image on the left (which happens to be a screen grab from safari) where the border width is more consistent. How does apple make their lines so perfect?
I'm using a CALayer and the Core Graphics API to draw the image on the right. Is it possible to draw such perfect lines with the standard apis?
The problem with drawing a 1-pixel path is that Quartz draws paths on an exact point grid, starting from {0,0}. This means that if you stroke a vertical path starting at {10,10} with a 1-point width, half of that line will render in the pixel to the left of the coordinate and half in the pixel to the right, causing a blurring effect.
You should therefore shift your drawing by {0.5,0.5} if you want lines to draw on exact pixels.
You can definitely draw what you want with Quartz.
Apple uses images for the tab elements.