Powered By Blogger

Thursday, January 20, 2011

UIImagePickerControler

 #pragma mark -
#pragma mark Camera Open Method

-(void)cameraCalling {
    UIImagePickerController *picker;

    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {  
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.cameraOverlayView = lblEvent;
        [picker setShowsCameraControls:YES];
    }
    else
    {
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    picker.allowsImageEditing =YES;
  
    [self presentModalViewController:picker animated:TRUE];
  
}



#pragma mark -
#pragma mark imagePickerController Methods

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;
{
    if (!error)
        NSLog(@"Image written to photo album");
    else
        NSLog(@"Error writing to photo album: %@", [error localizedDescription]);


}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    count ++;
    isRemoved = NO;
    capturedImg = image;
    imgView.image = image;
   
    NSData *imageData = UIImageJPEGRepresentation(image, 1.1);
    NSString *base64String=@"";
    if(imageData)
    {
        base64String=[imageData base64Encoding];
    }
   
    NSDate *date = [NSDate date];
    NSDateFormatter *df = [[NSDateFormatter alloc]init];
    [df setDateFormat:@"MM-dd-yyyy"];
    NSString *str1= [df stringFromDate:date];
    [df setTimeStyle:NSDateFormatterShortStyle];
    NSString *str2= [df stringFromDate:date];
   
    NSLog(@"%@ %@",str1,str2);
    appDelegate.fileName =[NSString stringWithFormat:@"%@ %@",str1,str2];
    [self saveImage:image :appDelegate.fileName];

   
    //UIImageWriteToSavedPhotosAlbum(image, picker, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissModalViewControllerAnimated:YES];

}