how to draw grid lines when camera is open avcapturemanager(打开相机时如何绘制网格线avcapturemanager)
问题描述
我想像打开相机时出现的那样显示网格线.我正在使用 AVCaptureManager.我应该使用核心图形来绘制网格线吗?这些网格线的大小是多少?
I want to display grid line like the one which appears when a camera is open.I am using AVCaptureManager.Should i use core graphics to draw grid lines?what is the size of those grid lines?
谢谢
推荐答案
您确实可以添加自定义视图作为覆盖在您的相机视图上,以使用 QuartzCore 绘制网格.
You can indeed add a custom view as an overlay over your camera view to draw the grid using QuartzCore.
这就是我在我的应用 Subvision 中的做法:
That is how I did it in my app Subvision:
我用来绘制它的代码(注意:我的网格是可调整的,所以它可以是 10x10、2x2 等):
The code I use to draw it (note: my grid is adjustable so it's can be 10x10, 2x2 etc):
// -------------------------------------------------------------------------------
// Used for drawing the grids ontop of the view port
// -------------------------------------------------------------------------------
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 0.5);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
// ---------------------------
// Drawing column lines
// ---------------------------
// calculate column width
CGFloat columnWidth = self.frame.size.width / (self.numberOfColumns + 1.0);
for(int i = 1; i <= self.numberOfColumns; i++)
{
CGPoint startPoint;
CGPoint endPoint;
startPoint.x = columnWidth * i;
startPoint.y = 0.0f;
endPoint.x = startPoint.x;
endPoint.y = self.frame.size.height;
CGContextMoveToPoint(context, startPoint.x, startPoint.y);
CGContextAddLineToPoint(context, endPoint.x, endPoint.y);
CGContextStrokePath(context);
}
// ---------------------------
// Drawing row lines
// ---------------------------
// calclulate row height
CGFloat rowHeight = self.frame.size.height / (self.numberOfRows + 1.0);
for(int j = 1; j <= self.numberOfRows; j++)
{
CGPoint startPoint;
CGPoint endPoint;
startPoint.x = 0.0f;
startPoint.y = rowHeight * j;
endPoint.x = self.frame.size.width;
endPoint.y = startPoint.y;
CGContextMoveToPoint(context, startPoint.x, startPoint.y);
CGContextAddLineToPoint(context, endPoint.x, endPoint.y);
CGContextStrokePath(context);
}
}
在我的 GridView 类中,我定义了 2 个属性 numberOfRows 和 numberOfColumns:
In my GridView class, I have defined 2 properties numberOfRows and numberOfColumns:
#import <UIKit/UIKit.h>
@interface GridView : UIView
@property (nonatomic, assign) int numberOfColumns;
@property (nonatomic, assign) int numberOfRows;
@end
这样做意味着我可以修改这两个值并拥有无限可调的网格细分.
Doing so means I can modify these two values and have infinitely adjustable grid subdivisions.
这篇关于打开相机时如何绘制网格线avcapturemanager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:打开相机时如何绘制网格线avcapturemanager


基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01