Using Objective C I need to combine 4 CMYK colors into one. - objective-c

Being an objective C newbie, and not much of a graphics programmer, I am struggling with the various graphic libraries apple supplies with the Xcode SDK ver 4.1. There are Cocoa, Open GL ES, Quartz 2D, and various other layers (frameworks) of high end and low end graphic functions. I just want to combine 4 specific colors and show them on the iPad, iPhone, iPod Touch.
I realize I can convert CMYK colors to RGBA without much difference from an optical point of view, but I guess combining colors into one color object in Objective C is my problem. I've looked at layering of views, blend modes of images in Quartz, etc. I'm not sure if I first need to create BMP files first, or what. I guess its all just a little overwhelming for a newbie, and I would appreciate some guidance on figuring out the graphic concept/terminology and then perhaps help choosing which graphics framework can do the job.

There is no reason to convert from CMYK to RGB. You just need to create your color using CGColor and a CYMK colorspace.
CGColorSpaceRef cmykColorSpace = CGColorSpaceCreateDeviceCMYK();
CGFloat colors[5] = {1, 1, 1, 1, 1}; // CMYK+Alpha
CGColorRef cgColor = CGColorCreate(cmykColorSpace, colors);
UIColor *uiColor = [UIColor colorWithCGColor:cgColor];
CGColorRelease(cgColor);
CGColorSpaceRelease(cmykColorSpace);
You can now use that color to do whatever you want.

Rob's answer is pretty cool - I never knew about that CGColorCreate function.
If you want to tweak the way the colors combine, you can use my category on UIColor - you can change the mixing algorithm in the class methods if you choose (the ones I coded are pretty good, I hope). This category also supports combining in RGB or RYB.
https://github.com/ddelruss/UIColor-Mixing
Enjoy,
Damien

Related

Cocoa / Mac OS: Get color of window toolbar

I'm making a Qt application where I need a tab widget in the exact color as the toolbar in Mac OS.
I'm not happy about just using a color picker to sample the color, as it might change slighty according to OS version. As I'm pretty sure this can't be done in Qt itself, I'm wondering if anyone knows how to do this natively?
I believe that [NSColor windowFrameColor] or one of the other class methods will get the color for the toolbar. you can get the RGB values from the NSColor if you need to after that. I'm not familiar with Qt, but you tagged this as obj-c so I assume this helps you.
Edit for gradients:
here is an explanation from an apple engineer how NSColor produces gradients.
[[NSColor selectedMenuItemColor] set];
NSRectFill(someRect);
This works because the selectedMenuItemColor is a pattern that happens to draw a gradient. You could just as easily draw nearly anything with a pattern, and Quartz treats patterns just like colors

program to plot UIBezierPaths?

I'm doing a lot of animations in iOS using UIBezierPaths and have been manually tweaking the control points until I get the curve I want. Is there a program I can buy that will let me tweak the path with handles like the PS pen tool does then map the control points for me or is there a way to take a curve drawn in PhotoShop, Illustrator, or the like and convert it somehow to a UIBezierPath.
Im wasting so much time tweaking these animations it seems like there has to be a better way.
UIBezierPath *runnerPath = [UIBezierPath bezierPath];
[runnerPath moveToPoint:P(1100, 463)];
[runnerPath addCurveToPoint:P(872, 357)
controlPoint1:P(967, 453)
controlPoint2:P(1022, 366)];
[runnerPath addCurveToPoint:P(503, 366)
controlPoint1:P(664, 372)
controlPoint2:P(699, 480)];
Answered by Kjuly: PaintCode, Perfect!
Try PaintCode:
Designing an attractive, resolution-independent user interface is hard, especially if you have to program your drawing code. PaintCode is a simple vector drawing app that instantly generates resolution-independent Objective-C and C#/MonoTouch drawing code.
Not tried, but I think it'll work as you want.
However, as you see, the price ($99) is so high. :$
So what I'll do in this case is drawing multiple lines together with different colors, select the best one to do the next drawing. Of course, it is better to do it with Photoshop or GIMP. Tedious work..

Motion Blur Emplementation on OpenGL ES

I'm a novice in OpenGL ES 1.1(for IOS) texturing and I have a problem with making the effect of motion blur. During googling, I found that I should render my scene in different time moments to several textures and then draw all these textures on the screen with different alpha values. But the problem is that I don't know how to implement all this!So,my questions are:
How to draw a 2D texture on the screen? Should I make a square and put my texture on it?Or may be, there is a way to draw a texture on the screen directly?
How to draw several textures(one upon another) on the screen with different alpha values?
I've already come up with some ideas, but I'm not sure if they are correct or not.
Thanks in advance!
Well, of course the first advice is, understand the basics before trying to do advanced stuff. Other than that:
Yes indeed, to draw a full-screen texture you just draw a textured screen-sized quad. An orthographic projection would be a good idea in this case, making the screen-alignment of the quad and its proper sizing easier. For getting the textures in the first place (by rendering into them), FBOs might be of help, but I'm not sure they are supported on ES 1 devices, otherwise the good old glCopyTexSubImage2D will do, too, albeit requiring a copy operation.
Well, you just draw multiple textured quads (see 1) one over the other. You might configure the texture environment to scale the texture's color with the quad's base color (glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)) and give your quads a color of (1, 1, 1, alpha) (of course lighting should be disabled). Additionally you have to enable alpha blending (glEnable(GL_BLEND)) and use an appropriate blending function (glBlendFunc(GL_SRC_ALPHA, GL_ONE) should do).
But if all these terms don't tell you anything, you should rather first learn the basics using a good learning resource before delving into more advanced effects.

How to make nice openGL blended lines in cocos2d?

i've written an algorithm to create electricity using ccDrawLine function in cocos2d for iphone. Currently, the ccDrawLine is a simple wrapper method for drawing openGL lines on the fly.
My algorithm is sound and works as I want. But the problem is with the appearance of the electricity in general.
I have little openGL programming knowledge(hence the use of the wrapper) and I require the ccLines to be blended nicely and look like either lasers or electricity.
How can I go about doing this avoiding the use of openGL programming if possible, otherwise i'll need to learn it.
you sample the surrounding pixels for each pixel of the area and average it out. This is the most basic way i know but it is not very fast so you could blend in 2x2 squares instead of 1x1 or even 4x4 and move over every iteration because for a nice effect you would do maybe 3 times.

QPainter equivalent in Objective C

I'm trying to translate a Qt project in Objective-C
It is a blockbraker.
I need to find the equivalent for QPainter, un Qt object that call the Windows fonction to draw something on the screen.
So I need anything that allows me to draw lines, ellipse and, most important of all, png images.
Thanks
You'll want to have a look at the Cocoa Drawing Guide, which explains how to draw things in Cocoa. Specifically, the NSBezierPath lets you draw shapes, and NSImage lets you work with PNGs. But there are other classes you need to know about in order to change colors, etc.