核心图形的图像效果
问题描述:
我想知道如何重现图像效果,我们可以在几种Mac和iPhone应用程序中看到它们全部从黑白图像开始: - 在iPhone上的UiTabbar中,黑色和当它被选中时,白色图片变成蓝色渐变 - 在Twitter上,对于mac,我们可以看到几种效果(发光,斜角,....)核心图形的图像效果
欢迎您就此主题提供任何帮助。 :)
编辑:我对MAC操作系统,而不是在iPhone上的这些影响感兴趣。
答
不幸的是,iOS缺乏MacOSX中的Core Image框架,它是所有这些美丽效果的来源。 UITabBar特效可以使用Core Graphics蒙板特征重新创建(例如参见
void CGContextClipToMask (
CGContextRef c,
CGRect rect,
CGImageRef mask
);
)。这是可能的,因为蒙版是基于图像阿尔法和所有标签栏按钮是基于阿尔法的(尝试在标签栏添加一个不是基于alpha的图像,你会看到最终的效果......)。 最后,您可以看看
GLImageProcessing包含在XCode文档或 here中的示例:这解释了如何使用OpenGL ES 1.1进行一些基本的图像处理(通过该示例包含一些基本的纹理和渲染方法,您可以重新使用以集成任何基于UIKit的应用程序中的OpenGL视图)。
答
我不认为有必要画这些,因为他们可以获得与其他软件(Photoshop,像素等)完成的图像相同。 为什么?因为(按钮的)内容不会改变,不会调整大小,所以图像很好看,也是最简单的方法。
如果您想了解如何使用Quartz进行绘制,Apple开发中心和/或Xcode中有许多文档和示例。
这是马特·加拉格尔最近的一个教程:Advanced drawing using AppKit
答
退房苹果QuartzDemo示例项目。 QuartzClipping类向您展示了如何使用剪裁和遮罩。这是我根据这个项目计算出来的结果。
CGContextRef context = UIGraphicsGetCurrentContext();
UIImage *img = [UIImage imageNamed:@"at.png"];
CGImageRef alphaImage = CGImageRetain(img.CGImage);
UIImage *backgroundImg = [UIImage imageNamed:@"gradientBackground.png"]; // background image for normal state
CGImageRef image = CGImageRetain(backgroundImg.CGImage);
CGFloat height = self.bounds.size.height;
CGContextTranslateCTM(context, 0.0, height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetRGBFillColor(context, 0.129, 0.129, 0.129, 1.0);
CGContextFillRect(context, self.bounds);
CGContextSaveGState(context);
CGContextClipToMask(context, CGRectMake(100.0, height - 150.0, img.size.width, img.size.height), alphaImage);
CGContextDrawImage(context, CGRectMake(100.0 - (backgroundImg.size.width-img.size.width)/2,
height - 150 - (backgroundImg.size.height-img.size.height)/2,
backgroundImg.size.width,
backgroundImg.size.height), image);
CGContextRestoreGState(context);
UIImage *backgroundImg2 = [UIImage imageNamed:@"TabBarItemSelectedBackground.png"]; // background image for selected state
CGImageRef image2 = CGImageRetain(backgroundImg2.CGImage);
CGContextSaveGState(context);
CGContextClipToMask(context, CGRectMake(180.0, height - 150.0, img.size.width, img.size.height), alphaImage);
CGContextDrawImage(context, CGRectMake(180.0 - (backgroundImg2.size.width-img.size.width)/2,
height - 150.0 - (backgroundImg2.size.height-img.size.height)/2,
backgroundImg2.size.width,
backgroundImg2.size.height), image2);
CGContextRestoreGState(context);
CGImageRelease(image);
CGImageRelease(alphaImage);
CGImageRelease(image2);
问题是如何从代码中获取它,而不是使用photoshop。不,没有很多这种效果的文档。关于你的教程,它不是由Matt Gemmell编写的(但是他编写代码的宝石) – 2011-02-06 11:56:25