1
調整拍攝的圖像,我將要拍攝的圖像進行實時疊加就像魔方的狗是如何工作的 - 下面做過代碼按照此處http://www.musicalgeometry.com/?p=1681如何使用覆蓋
我知道如何覆蓋在預覽圖像圖層和捕捉圖像,我看着蘋果示例代碼,如果在相機膠捲中檢測到臉部,它將保存一個紅色方框。
編輯:
我會想將它保存在1920×1080的後置攝像頭和1280 X 960,下面的代碼工作節省實時疊加和圖像但卻對準被關閉,我不知道爲什麼有人可以幫忙嗎?
歡呼
這是捕捉
- (id)init {
if ((self = [super init])) {
[self setCaptureSession:[[AVCaptureSession alloc] init]];
[self.captureSession setSessionPreset:AVCaptureSessionPresetHigh];
}
NSLog(@"init called");
return self;
}
-(void)takePictureWithOverlay:(UIImage*)overlay andRect:(CGRect)overlayRect
{
// Find out the current orientation and tell the still image output.
AVCaptureConnection *stillImageConnection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
//UIDeviceOrientation curDeviceOrientation = [[UIDevice currentDevice] orientation];
// AVCaptureVideoOrientation avcaptureOrientation = [self avOrientationForDeviceOrientation:curDeviceOrientation];
[stillImageConnection setVideoOrientation:AVCaptureVideoOrientationPortrait];
[stillImageConnection setVideoScaleAndCropFactor:self.effectiveScale];
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:stillImageConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (error) {
[self displayErrorOnMainQueue:error withMessage:@"Take picture failed"];
}
else {
// trivial simple JPEG case
NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:jpegData];
/////
CGSize imageSize = [image size];
CGSize overlaySize = [overlay size];
UIGraphicsBeginImageContext(imageSize);
[image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
NSLog(@"aaa %f", [UIScreen mainScreen].applicationFrame.size.width);
NSLog(@"aaa %f", [UIScreen mainScreen].applicationFrame.size.height);
NSLog(@"aaa %f", [[UIScreen mainScreen] bounds].size.height);
CGFloat xScaleFactor = imageSize.width/320;//320;
CGFloat yScaleFactor = imageSize.height/568;//480;//568;
NSLog(@"xScaleFactor size %F",xScaleFactor);
NSLog(@"yScaleFactor size %F",yScaleFactor);
//144 for 568
[overlay drawInRect:CGRectMake(overlayRect.origin.x * xScaleFactor, overlayRect.origin.y*yScaleFactor
, overlaySize.width * xScaleFactor, overlaySize.height * yScaleFactor)]; // rect used in AROverlayViewController was (30,100,260,200)
UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();
[self setStillImage:combinedImage];
UIGraphicsEndImageContext();
/////
}
[[NSNotificationCenter defaultCenter] postNotificationName:kImageCapturedSuccessfully object:nil];
}];
}
通過實時你的意思是編程需要,並保存圖像(無需用戶動作)? –
嗨斯里卡, 我的意思是,我想保存它,一旦用戶點擊快門按鈕並保存在一起的覆蓋 – Desmond