//- (CGPoint)convertToPointOfInterestFromViewCoordinates:(CGPoint)viewCoordinates
//{
// CGPoint pointOfInterest = CGPointMake(.5f, .5f);
// CGSize frameSize = [self.view frame].size;
//
// AVCaptureVideoPreviewLayer *videoPreviewLayer = [self previewLayer];
//
// if ([[self previewLayer] isMirrored]) {
// viewCoordinates.x = frameSize.width - viewCoordinates.x;
// }
//
// if ( [[videoPreviewLayer videoGravity] isEqualToString:AVLayerVideoGravityResize] ) {
// pointOfInterest = CGPointMake(viewCoordinates.y / frameSize.height, 1.f - (viewCoordinates.x / frameSize.width));
// } else {
// CGRect cleanAperture;
// for (AVCaptureInputPort *port in [[[[self captureSession] inputs] lastObject] ports]) {
// if ([port mediaType] == AVMediaTypeVideo) {
// cleanAperture = CMVideoFormatDescriptionGetCleanAperture([port formatDescription], YES);
// CGSize apertureSize = cleanAperture.size;
// CGPoint point = viewCoordinates;
//
// CGFloat apertureRatio = apertureSize.height / apertureSize.width;
// CGFloat viewRatio = frameSize.width / frameSize.height;
// CGFloat xc = .5f;
// CGFloat yc = .5f;
//
// if ( [[videoPreviewLayer videoGravity] isEqualToString:AVLayerVideoGravityResizeAspect] ) {
// if (viewRatio > apertureRatio) {
// CGFloat y2 = frameSize.height;
// CGFloat x2 = frameSize.height * apertureRatio;
// CGFloat x1 = frameSize.width;
// CGFloat blackBar = (x1 - x2) / 2;
// if (point.x >= blackBar && point.x <= blackBar + x2) {
// xc = point.y / y2;
// yc = 1.f - ((point.x - blackBar) / x2);
// }
// } else {
// CGFloat y2 = frameSize.width / apertureRatio;
// CGFloat y1 = frameSize.height;
// CGFloat x2 = frameSize.width;
// CGFloat blackBar = (y1 - y2) / 2;
// if (point.y >= blackBar && point.y <= blackBar + y2) {
// xc = ((point.y - blackBar) / y2);
// yc = 1.f - (point.x / x2);
// }
// }
// } else if ([[videoPreviewLayer videoGravity] isEqualToString:AVLayerVideoGravityResizeAspectFill]) {
// if (viewRatio > apertureRatio) {
// CGFloat y2 = apertureSize.width * (frameSize.width / apertureSize.height);
// xc = (point.y + ((y2 - frameSize.height) / 2.f)) / y2;
// yc = (frameSize.width - point.x) / frameSize.width;
// } else {
// CGFloat x2 = apertureSize.height * (frameSize.height / apertureSize.width);
// yc = 1.f - ((point.x + ((x2 - frameSize.width) / 2)) / x2);
// xc = point.y / frameSize.height;
// }
//
// }
//
// pointOfInterest = CGPointMake(xc, yc);
// break;
// }
// }
// }
//
// return pointOfInterest;
//}
convertToPointOfInterestFromViewCoordinates
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...