早在大二上学期初, 就有独立制作一款摄影类 app 的打算, 但是那是时间不多能力不足也就搁浅了后来中途接触了类似于 HUJI Poly Filmborn 等优秀摄影类 app 的时候心里那头小鹿又开始乱撞, 于是便开始了翻资料码代码的生活, 以下是我运用 GPUImage 框架制作一款相机 app(暂时还未上架)的过程遇到过的坑, 希望对你有所帮助
一关于 GPUImage
官方描述: The GPUImage framework is a BSD-licensed iOS library that lets you apply GPU-accelerated filters and other effects to images, live camera video, and movies. In comparison to Core Image (part of iOS 5.0), GPUImage allows you to write your own custom filters, supports deployment to iOS 4.0, and has a simpler interface. However, it currently lacks some of the more advanced features of Core Image, such as facial detection. GPUImage 是使用 GPU 处理图像的他可以对图片实时画面视频进行处理他允许你自定义滤镜支持 iOS4.0 然而, 目前缺乏核心形象的一些更高级的功能, 比如面部检测
GPUImage 框架能排入 ios 框架排行榜的前十, 是名副其实的 ios 老牌框架, 由于目前的直播以及美颜类相机 app 的大火, GPUImage 框架也是制作这些 app 时的不二之选
二 Q&A(问题与解决办法)
Q1:linker command failed with exit code 1 (use -v to see invocation)问题的解决办法
A1:cocopods 导入后记得关闭整个项目然后从. xcworkspace 文件进入
点击此文件进入
Q2: 制作模拟相机界面时如何隐去 status bar 让主界面全屏显示
A2: info.plist->Status bar is initially hidden-YES;View controller-based status bar appearance-NO;
Status bar is initially hidden-YES
View controller-based status bar appearance-NO
Q3: 错误提示 Failed to read file attributes for "/Users/zhangyunzhu/Downloads/XRWaterfallLayout-master/XRWaterfallLayoutDemo/XRWaterFallLayoutDemo/Assets.xcassets"
A3: 删除 Assets.xcassets 里面变红的图片文件
Q4:image.JPG 找不到警告
A4: 由于大多数的图片素材都都来源于网络, 图片格式结尾层次不齐如. jpg .JPG .svg .png 等等, 所以注意大小写 注意大小写 注意大小写 重要的事情说三遍, 哦对了, 还有间隔符也要看一下, 能删则删代码里面 imageNamed 看得出区别
Q5: 在从 github 上导入项目时候显示如图错误(很常见)
常见错误
A5: 由于苹果官方的限制每周提供给开发者的 Bundle Identifier 有限, 建议在创建好新的工程并且顺利运行之后保存一下 BI 码供其他项目使用
Q6:The app's Info.plist must contain an NSPhotoLibraryAddUsageDescription key with a string value explaining to the user how the app uses this data. 问题
A6:info.plist-Photo Library Additions Usage Description - 想访问图库
info.plist
Q7: 关于相机 app 拍摄后实际生成图片的方向和拍摄时的的方向不一致的问题
A7: 实际上 iOS 手机竖着拍出的照片与横着拍出的照片对于拍摄者来说是一样的, 只不过竖着拍出的照片被添加了一个顺时针旋转 90° 的拍照方向, 所以显示的时候, 就变成了上下边窄左右边宽的状态, 其实也就是横着拍的照片顺时针旋转 90° 而成的
比如这样:
拍摄时所呈现的图片方向
保存在相册时的图片方向
这里参考文章: https://www.cnblogs.com/gaoxiaoniu/p/5329834.html
- - (UIImage * ) normalizedImage {
- if (self.imageOrientation == UIImageOrientationUp) return self; UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale); [self drawInRect: (CGRect) {
- 0,
- 0,
- self.size
- }]; UIImage * normalizedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
- return normalizedImage;
- }
代码大致的意思是获取所拍摄下来的照片的方位, 如果方位不是 UIImageOrientationUp, 那么则将它重新绘制在画板上, 此时 drawInRect 会和系统图库一样将他
这里多插一句, ios 相机拍照时原始方向是 home 键向右的方向而并不是平时刷微信的 home 键朝下的方向
方向参数图
但是, 这个方法可能会有画质上的损失这里有个更好的方法:
减小画质损失方法
- CGSize size = {390, 430}; // 新手注意: CGSize 是一个结构体类型, 不是对象, 所以变量前不加'*'号;
- if([[UIScreen mainScreen] scale] == 2.0){ // @2x
- UIGraphicsBeginImageContextWithOptions(size, NO, 2.0);
- }else if([[UIScreen mainScreen] scale] == 3.0){ // @3x ( iPhone 6plus iPhone 6s plus)
- UIGraphicsBeginImageContextWithOptions(size, NO, 3.0);
- }else{
- UIGraphicsBeginImageContext(size);
- }
- // 绘制改变大小的图片
- [imager drawInRect:CGRectMake(100, 0, size.width, size.height)];
- // 从当前 context 中创建一个改变大小后的图片
- UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
- // 使当前的 context 出堆栈
- UIGraphicsEndImageContext();
- // 返回新的改变大小后的图片
- imager = scaledImage;
- // 处理按钮点击事件
- [self.testbtn addTarget:self action:@selector(TouchDown)forControlEvents: UIControlEventTouchDownInside];
- // 处理按钮松开状态
- [self.testbtn addTarget:self action:@selector(TouchUp)forControlEvents: UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
- // 2. 在 appdelegate.m 里写处理点击 3D touch 方法的功能实现
- -(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
- if ([shortcutItem.type isEqualToString:@"Camera"]) {
- NSLog(@"开拍");
- }
来源: http://www.jianshu.com/p/94516b9807a5