开发者

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

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 overwh开发者_开发技巧elming 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜