Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

karthees

macrumors newbie
Original poster
Mar 27, 2013
1
0
I have a code for capture overlay image. But when i move my overlay image then i need take a picture. My problem is i set overlay image frame size is in drawInRect. So It will take only drawInRect size. I moved my overlay image then i took snapshot. It captured only default value what i set in drawInRect. I need to capture new position.

Code:
- (void)captureStillImageWithOverlay:(UIImage*)overlay
{
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in [[self stillImageOutput] connections]) {
for (AVCaptureInputPort *port in [connection inputPorts]) {
if ([[port mediaType] isEqual:AVMediaTypeVideo]) {
videoConnection = connection;
break;
}
}
if (videoConnection) {
            break;
        }
}
 
NSLog(@"about to request a capture from: %@", [self stillImageOutput]);        
 
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection
                                                         completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
                                                             CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
                                                             if (exifAttachments) {
                                                                 NSLog(@"attachements: %@", exifAttachments);
                                                             } else {
                                                                 NSLog(@"no attachments");
                                                             }
 
                                                             NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
                                                             UIImage *image = [[UIImage alloc] initWithData:imageData];
 
 
                                                           CGSize imageSize = [image size];
 
                                                            CGSize overlaySize = [overlay size];
 
                                                            UIGraphicsBeginImageContext(imageSize);
 
 
                                                             [image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
 
                                                             CGFloat xScaleFactor = imageSize.width / 320;
                                                             CGFloat yScaleFactor = imageSize.height / 480;                                                          
                                                                                                                
                                                                                                                
                                                            [overlay drawInRect:CGRectMake(30 * xScaleFactor, 100 * yScaleFactor, overlaySize.width * xScaleFactor, overlaySize.width* yScaleFactor)];
                                                                                                                                                                            
                                                            UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();
 
                                                             [self setStillImage:combinedImage];
 
                                                             UIGraphicsEndImageContext();                                                                                                                
                                                                                                                                                                           
                                                            [image release];
                                                             [[NSNotificationCenter defaultCenter] postNotificationName:kImageCapturedSuccessfully object:nil];
                                                        }];     
 
                                                    }
 
Last edited by a moderator:

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
I have a code for capture overlay image. But when i move my overlay image then i need take a picture. My problem is i set overlay image frame size is in drawInRect. So It will take only drawInRect size. I moved my overlay image then i took snapshot. It captured only default value what i set in drawInRect. I need to capture new position.

Code:
- (void)captureStillImageWithOverlay:(UIImage*)overlay
{
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in [[self stillImageOutput] connections]) {
for (AVCaptureInputPort *port in [connection inputPorts]) {
if ([[port mediaType] isEqual:AVMediaTypeVideo]) {
videoConnection = connection;
break;
}
}
if (videoConnection) {
            break;
        }
}
 
NSLog(@"about to request a capture from: %@", [self stillImageOutput]);        
 
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection
                                                         completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
                                                             CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
                                                             if (exifAttachments) {
                                                                 NSLog(@"attachements: %@", exifAttachments);
                                                             } else {
                                                                 NSLog(@"no attachments");
                                                             }
 
                                                             NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
                                                             UIImage *image = [[UIImage alloc] initWithData:imageData];
 
 
                                                           CGSize imageSize = [image size];
 
                                                            CGSize overlaySize = [overlay size];
 
                                                            UIGraphicsBeginImageContext(imageSize);
 
 
                                                             [image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
 
                                                             CGFloat xScaleFactor = imageSize.width / 320;
                                                             CGFloat yScaleFactor = imageSize.height / 480;                                                          
                                                                                                                
                                                                                                                
                                                            [overlay drawInRect:CGRectMake(30 * xScaleFactor, 100 * yScaleFactor, overlaySize.width * xScaleFactor, overlaySize.width* yScaleFactor)];
                                                                                                                                                                            
                                                            UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();
 
                                                             [self setStillImage:combinedImage];
 
                                                             UIGraphicsEndImageContext();                                                                                                                
                                                                                                                                                                           
                                                            [image release];
                                                             [[NSNotificationCenter defaultCenter] postNotificationName:kImageCapturedSuccessfully object:nil];
                                                        }];     
 
                                                    }


I don't understand what you are saying. What do you mean "capture an overlay image?" And what does your sentence "So It will take only drawInRect size" mean? Also, your code is all but impossible to read. 80% of it is scrolled off the right edge of the code scroll-view. You should strip out excess indentation and clean up code when you post it so your readers can understand."

Finally, it looks like you are using a number of custom classes and methods that you don't explain.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.