capture overlay image whenever image move new position or new scale

Discussion in 'iOS Programming' started by karthees, Mar 27, 2013.

  1. karthees, Mar 27, 2013
    Last edited by a moderator: Mar 27, 2013

    karthees macrumors newbie

    Joined:
    Mar 27, 2013
    #1
    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];
                                                            }];     
     
                                                        }
     
  2. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #2

    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.
     

Share This Page