2015-01-21 1 views
1

응용 프로그램의 특정 부분에서 사용자가 카메라에서 사진을 찍거나 앨범에서 사진을 찍을 수 있으며이 이미지가 표시됩니다. ViewController에. 이것은 쉽지만, 내가 할 수없는 일은 다음과 같습니다. - 카메라를 전체 화면으로 열지 않고 ViewController에서 '열어'싶습니다. 사용자는 이미지가있는 곳과 정확히 같은 곳에 원 안에 있습니다. 카메라를 전체 화면으로 열 수 없도록 만들었지 만이보기를 원보기 안에 넣고 원에 따라 사진을자를 수는 없습니다. 여기 사용자 정의 카메라가 전체 화면이 아닌 UIView에 있음

는 표준 프로젝트를 만드는 경우가 작동하지 않을 수 있습니다, 내 코드와 나는 그에서 무슨 일이 일어나고 있는지 이해하는 데 도움이 될 것입니다 생각 :

@property (nonatomic, strong) UIImagePickerController * picker; 
@property (nonatomic, strong) UIImageView    * photoView; 
@property (nonatomic, strong) UIView     * overlayView; 
@property (nonatomic, strong) UIButton * takePhotoButton; //- function 
@property (nonatomic, strong) UIButton * selectPhotoButton; 
@property (nonatomic, strong) UIButton * takePicture; //- action 

CODE

@interface CameraViewController() 
{ 
    BOOL isFromAlbum; 
} 

@end 

@implementation CameraViewController 

@synthesize photoView; 
@synthesize picker; 
@synthesize takePicture; 
@synthesize selectPhotoButton; 
@synthesize takePhotoButton; 
@synthesize overlayView; 
@synthesize switchCameraButton; 

#pragma mark - 
#pragma mark Initialization & Life Cycle 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self initInterface]; 
} 
-(void)initInterface 
{ 
    [super addBackButton]; 

    self.view.backgroundColor     = [UIColor colorWithRed:026.0f/255.0f green:030.0f/255.0f blue:055.0f/255.0f alpha:1.0f]; 

    self.takePhotoButton      = [UIButton buttonWithType:UIButtonTypeSystem]; 
    self.takePhotoButton.frame     = CGRectMake(27.5f, self.view.frame.size.width/2 - 55, 110, 110); 
    self.takePhotoButton.layer.cornerRadius  = self.takePhotoButton.frame.size.width/2.0f; 
    [self.takePhotoButton setImage:[UIImage imageNamed:@"take-photo-btn"] forState:UIControlStateNormal]; 
    [self.takePhotoButton addTarget:self action:@selector(takePhotoFunction) forControlEvents:UIControlEventTouchUpInside]; 
    //[self.takePhotoButton setBackgroundColor:[UIColor colorWithRed:000.0f/255.0f green:255.0f/255.0f blue:000.0f/255.0f alpha:0.25f]]; 
    [self.view addSubview:self.takePhotoButton]; 

    self.selectPhotoButton      = [UIButton buttonWithType:UIButtonTypeSystem]; 
    self.selectPhotoButton.frame    = CGRectMake(self.view.frame.size.width/2 + 27.5f, self.view.frame.size.width/2 - 55, 110, 110); 
    self.selectPhotoButton.layer.cornerRadius = self.selectPhotoButton.frame.size.width/2.0f; 
    [self.selectPhotoButton setImage:[UIImage imageNamed:@"pick-photo-btn"] forState:UIControlStateNormal]; 
    [self.selectPhotoButton addTarget:self action:@selector(selectPhoto) forControlEvents:UIControlEventTouchUpInside]; 
    //[self.selectPhotoButton setBackgroundColor:[UIColor colorWithRed:0 green:255/255.0f blue:0 alpha:0.25f]]; 
    [self.view addSubview:self.selectPhotoButton]; 


    self.photoView        = [[UIImageView alloc] init]; 
    self.photoView.backgroundColor    = [UIColor colorWithRed:255.0f/255.0f green:000.0f/255.0f blue:000.0f/255.0f alpha:0.25f]; 
    self.photoView.frame      = CGRectMake(0, 0, 320, 320); 
    self.photoView.layer.cornerRadius   = self.photoView.frame.size.width/2; 
    self.photoView.layer.masksToBounds   = YES; 
    self.photoView.userInteractionEnabled  = YES; 
} 

#pragma mark - 
#pragma mark Button's Actions 
- (void)takePhotoFunction 
{ 
    self.picker      = [[UIImagePickerController alloc] init]; 
    self.picker.delegate   = self; 
    self.picker.allowsEditing  = YES; 
    self.picker.sourceType   = UIImagePickerControllerSourceTypeCamera; 
    self.picker.showsCameraControls = NO; 
    self.picker.view.frame   = self.photoView.bounds; 
    [self.photoView addSubview:self.picker.view]; 

    self.takePicture     = [UIButton buttonWithType:UIButtonTypeSystem]; 
    self.takePicture.frame    = CGRectMake(self.photoView.frame.size.width/2 - 35, self.photoView.frame.size.height - 70, 70, 70); 
    [self.takePicture addTarget:self action:@selector(takePhotoAction:) forControlEvents:UIControlEventTouchUpInside]; 
    [self.takePicture setBackgroundImage:[UIImage imageNamed:@"take-photo-action"] forState:UIControlStateNormal]; 
    [self.photoView addSubview:self.takePicture]; 

    self.switchCameraButton = [[UIButton alloc] init]; 
    self.switchCameraButton.frame    = CGRectMake(self.photoView.frame.size.width/2 - 35, self.photoView.frame.origin.y, 70, 70); 
    [self.switchCameraButton addTarget:self action:@selector(switchCamera:) forControlEvents:UIControlEventTouchUpInside]; 
    [self.switchCameraButton setBackgroundImage:[UIImage imageNamed:@"reverse-camera-btn"] forState:UIControlStateNormal]; 
    [self.photoView addSubview:self.switchCameraButton]; 


    [self.view addSubview:self.photoView]; 
    isFromAlbum = NO; 
} 

- (void)selectPhoto 
{ 
    self.picker = [[UIImagePickerController alloc] init]; 
    self.picker.delegate = self; 
    self.picker.allowsEditing = YES; 
    self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

    isFromAlbum = YES; 

    [self presentViewController:self.picker animated:YES completion:NULL]; 
} 

-(IBAction)takePhotoAction:(id)sender 
{ 
    [self.picker takePicture]; 
} 

-(IBAction)switchCamera:(id)sender 
{ 
    if (picker.cameraDevice == UIImagePickerControllerCameraDeviceFront) 
    { 
     picker.cameraDevice = UIImagePickerControllerCameraDeviceRear; 
    } 
    else if (picker.cameraDevice == UIImagePickerControllerCameraDeviceRear) 
    { 
     picker.cameraDevice = UIImagePickerControllerCameraDeviceFront; 
    } 
} 

#pragma mark - 
#pragma mark PickerController Delegate Methods 
- (void)imagePickerController:(UIImagePickerController *)myPicker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    //NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; 
    UIImage *originalImage, *editedImage, *imageToSave; 

    // Handle a still image capture 
    //if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) 
    if (isFromAlbum == NO) 
    { 
     editedImage = (UIImage *) [info objectForKey: 
            UIImagePickerControllerEditedImage]; 
     originalImage = (UIImage *) [info objectForKey: 
            UIImagePickerControllerOriginalImage]; 

     if (editedImage) 
     { 
      imageToSave = editedImage; 
     } 
     else 
     { 
      imageToSave = originalImage; 
     } 

     // Save the new image (original or edited) to the Camera Roll 
     //UIImageWriteToSavedPhotosAlbum (imageToSave, nil, nil , nil); 
     [self.takePhotoButton removeFromSuperview]; 
     [self.switchCameraButton removeFromSuperview]; 
     [self.selectPhotoButton removeFromSuperview]; 
     [self.picker.view removeFromSuperview]; 
     [self.takePicture removeFromSuperview]; 


     CGFloat minimumSide = fminf(imageToSave.size.width, imageToSave.size.height); 
     CGFloat finalSquareSize = 640.; 

     //create new drawing context for right size 
     CGRect rect = CGRectMake(0, 0, finalSquareSize, finalSquareSize); 
     CGFloat scalingRatio = 640.0/minimumSide; 
     UIGraphicsBeginImageContext(rect.size); 

     //draw 
     [imageToSave drawInRect:CGRectMake((minimumSide - originalImage.size.width)*scalingRatio/2., (minimumSide - originalImage.size.height)*scalingRatio/2., originalImage.size.width*scalingRatio, originalImage.size.height*scalingRatio)]; 

     UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext(); 

     UIGraphicsEndImageContext(); 



     //[self.photoView setImage:imageToSave]; 
     [self.photoView setImage:croppedImage]; 
    } 
    else 
    { 
     [self.takePhotoButton removeFromSuperview]; 
     [self.selectPhotoButton removeFromSuperview]; 
     UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; 
     [self.photoView setImage:chosenImage]; 
     [self.view addSubview:self.photoView]; 
     [myPicker dismissViewControllerAnimated:YES completion:NULL]; 
    } 
} 

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)myPicker 
{ 
    //[picker.view removeFromSuperview]; 
    [myPicker dismissViewControllerAnimated:YES completion:NULL]; 
} 

#pragma mark - 
#pragma mark NavigationController Methods 
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
{ 
    [[UIApplication sharedApplication] setStatusBarHidden:NO]; 
} 
+0

그럼, 당신이이 시점에서 **을 받고 ** 결과 : 여기

는 fullcode입니까? – mbm29414

+0

앨범에서 사진을 찍거나 사진을 선택하여 내 화면에 표시 할 수 있습니다 (서클/자르기에 맞게 편집하지 않아도 됨). –

+0

코드가 업데이트되었습니다. 이제 이미지는 괜찮지 만 조금 올라간다. –

답변

1

VARIABLES 아래 코드를 사용하면 다음과 같은 결과가 나타납니다.

  1. 어두운 파란색 배경의 단일보기입니다.
  2. 2 개의 녹색 원 (버튼)
  3. 왼쪽 원을 탭하면 카메라의 "광경"이 내부에 놓입니다.
  4. "테이크"버튼 (왼쪽 원의 아래쪽)을 누르면 "takePhotoAction"메소드가 실행됩니다.

[코드]

// ViewController.m 
    #import "ViewController.h" 
    @interface ViewController() <UIImagePickerControllerDelegate, UINavigationControllerDelegate> { 
     BOOL isFromAlbum; 
    } 
    @property (nonatomic, strong) UIImagePickerController * picker; 
    @property (nonatomic, strong) UIImageView    * photoView; 
    @property (nonatomic, strong) UIView     * overlayView; 
    @property (nonatomic, strong) UIButton * takePhotoButton; //- function 
    @property (nonatomic, strong) UIButton * selectPhotoButton; 
    @property (nonatomic, strong) UIButton * takePicture; //- action 

    @end 

@implementation ViewController 

#pragma mark - 
#pragma mark Initialization & Life Cycle 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self initInterface]; 
} 
-(void)initInterface { 
    self.view.backgroundColor     = [UIColor colorWithRed:026.0f/255.0f green:030.0f/255.0f blue:055.0f/255.0f alpha:1.0f]; 

    self.takePhotoButton      = [UIButton buttonWithType:UIButtonTypeSystem]; 
    self.takePhotoButton.frame     = CGRectMake(27.5f, self.view.frame.size.width/2 - 55, 110, 110); 
    self.takePhotoButton.layer.cornerRadius  = self.takePhotoButton.frame.size.width/2.0f; 
    [self.takePhotoButton setImage:[UIImage imageNamed:@"take-photo-btn"] forState:UIControlStateNormal]; 
    [self.takePhotoButton addTarget:self action:@selector(takePhotoFunction) forControlEvents:UIControlEventTouchUpInside]; 
    [self.takePhotoButton setBackgroundColor:[UIColor colorWithRed:000.0f/255.0f green:255.0f/255.0f blue:000.0f/255.0f alpha:0.25f]]; 
    [self.view addSubview:self.takePhotoButton]; 

    self.selectPhotoButton      = [UIButton buttonWithType:UIButtonTypeSystem]; 
    self.selectPhotoButton.frame    = CGRectMake(self.view.frame.size.width/2 + 27.5f, self.view.frame.size.width/2 - 55, 110, 110); 
    self.selectPhotoButton.layer.cornerRadius = self.selectPhotoButton.frame.size.width/2.0f; 
    [self.selectPhotoButton setImage:[UIImage imageNamed:@"pick-photo-btn"] forState:UIControlStateNormal]; 
    [self.selectPhotoButton addTarget:self action:@selector(selectPhoto) forControlEvents:UIControlEventTouchUpInside]; 
    [self.selectPhotoButton setBackgroundColor:[UIColor colorWithRed:0 green:255/255.0f blue:0 alpha:0.25f]]; 
    [self.view addSubview:self.selectPhotoButton]; 


    self.photoView        = [[UIImageView alloc] init]; 
    self.photoView.backgroundColor    = [UIColor colorWithRed:255.0f/255.0f green:000.0f/255.0f blue:000.0f/255.0f alpha:0.25f]; 
    self.photoView.frame      = self.takePhotoButton.frame; 
    self.photoView.layer.cornerRadius   = self.photoView.frame.size.width/2; 
    self.photoView.layer.masksToBounds   = YES; 
    [self.photoView setUserInteractionEnabled:YES]; 
} 
#pragma mark - 
#pragma mark Actions 
- (void)takePhotoFunction { 
    self.picker      = [[UIImagePickerController alloc] init]; 
    self.picker.delegate   = self; 
    self.picker.allowsEditing  = YES; 
    self.picker.sourceType   = UIImagePickerControllerSourceTypeCamera; 
    self.picker.showsCameraControls = NO; 
    self.picker.view.frame   = self.photoView.bounds; 
    [self.photoView addSubview:self.picker.view]; 

    self.takePicture     = [UIButton buttonWithType:UIButtonTypeSystem]; 
    self.takePicture.frame    = CGRectMake(self.photoView.frame.size.width/2 - 35, self.photoView.frame.size.height - 40, 70, 70); 
    [self.takePicture addTarget:self action:@selector(takePhotoAction:) forControlEvents:UIControlEventTouchUpInside]; 
    [self.takePicture setBackgroundImage:[UIImage imageNamed:@"take-photo-action"] forState:UIControlStateNormal]; 
    [self.photoView addSubview:self.takePicture]; 

    [self.view addSubview:self.photoView]; 
    isFromAlbum = NO; 
} 
- (void)selectPhoto { 
    self.picker = [[UIImagePickerController alloc] init]; 
    self.picker.delegate = self; 
    self.picker.allowsEditing = YES; 
    self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

    isFromAlbum = YES; 

    [self presentViewController:self.picker animated:YES completion:NULL]; 
} 

-(IBAction)takePhotoAction:(id)sender { 
    [self.picker takePicture]; 
} 
#pragma mark - 
#pragma mark PickerController Delegate Methods 
- (void)imagePickerController:(UIImagePickerController *)myPicker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    //NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; 
    UIImage *originalImage, *editedImage, *imageToSave; 

    // Handle a still image capture 
    //if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) 
    if (isFromAlbum == NO) { 
     editedImage = (UIImage *) [info objectForKey: 
            UIImagePickerControllerEditedImage]; 
     originalImage = (UIImage *) [info objectForKey: 
            UIImagePickerControllerOriginalImage]; 

     if (editedImage) { 
      imageToSave = editedImage; 
     } else { 
      imageToSave = originalImage; 
     } 

     // Save the new image (original or edited) to the Camera Roll 
     //UIImageWriteToSavedPhotosAlbum (imageToSave, nil, nil , nil); 
     [self.takePhotoButton removeFromSuperview]; 
     [self.selectPhotoButton removeFromSuperview]; 
     [self.picker.view removeFromSuperview]; 
     [self.takePicture removeFromSuperview]; 
     [self.photoView setImage:imageToSave]; 

    } else { 
     [self.takePhotoButton removeFromSuperview]; 
     [self.selectPhotoButton removeFromSuperview]; 
     UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; 
     [self.photoView setImage:chosenImage]; 
     [self.view addSubview:self.photoView]; 
     [myPicker dismissViewControllerAnimated:YES completion:NULL]; 
    } 
} 
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)myPicker { 
    //[picker.view removeFromSuperview]; 
    [myPicker dismissViewControllerAnimated:YES completion:NULL]; 
} 
#pragma mark - 
#pragma mark NavigationController Methods 
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { 
    [[UIApplication sharedApplication] setStatusBarHidden:NO]; 
} 
@end 
+0

카메라의 "광경"을 '사각형'대신 원으로 표시해야합니다. –

+0

또한 사진을 찍은 후 사용자가 찍은 사진 (카메라의 원 안에있는 원 안에있는 것)이 카메라의 "광경"자체를 대체합니다. –

+0

내 코드를 복사 했습니까? 카메라의 "시력"을 원안에보고, "찍기"버튼 (카메라의 "광경"하단)을 누르면 해당 원이 찍힌 사진으로 바뀝니다. – mbm29414

0

정사각형으로 잘라내어 사진을 촬영 한 후에서 PhotoView의 "작은 화상」의 문제를 해결하고 바로 뒤에 상기에서 PhotoView의 화상을 설정.

x : 0, y : -50, PhotoView.width, PhotoView.height에서 picker.view 프레임을 '설정'하여 PhotoView에서 이미지를 설정 한 후 이미지가 조금씩 올라가는 문제가 해결되었습니다.

@interface CameraViewController() 
{ 
    BOOL isFromAlbum; 
} 

@end 

@implementation CameraViewController 

@synthesize photoView; 
@synthesize picker; 
@synthesize takePicture; 
@synthesize selectPhotoButton; 
@synthesize takePhotoButton; 
@synthesize switchCameraButton; 

#pragma mark - 
#pragma mark Initialization & Life Cycle 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self initInterface]; 
} 
-(void)initInterface 
{ 
    [super addBackButton]; 

    self.view.backgroundColor     = [UIColor colorWithRed:026.0f/255.0f green:030.0f/255.0f blue:055.0f/255.0f alpha:1.0f]; 

    self.takePhotoButton      = [UIButton buttonWithType:UIButtonTypeSystem]; 
    self.takePhotoButton.frame     = CGRectMake(27.5f, self.view.frame.size.width/2 - 55, 110, 110); 
    self.takePhotoButton.layer.cornerRadius  = self.takePhotoButton.frame.size.width/2.0f; 
    [self.takePhotoButton setImage:[UIImage imageNamed:@"take-photo-btn"] forState:UIControlStateNormal]; 
    [self.takePhotoButton addTarget:self action:@selector(takePhotoFunction) forControlEvents:UIControlEventTouchUpInside]; 
    //[self.takePhotoButton setBackgroundColor:[UIColor colorWithRed:000.0f/255.0f green:255.0f/255.0f blue:000.0f/255.0f alpha:0.25f]]; 
    [self.view addSubview:self.takePhotoButton]; 

    self.selectPhotoButton      = [UIButton buttonWithType:UIButtonTypeSystem]; 
    self.selectPhotoButton.frame    = CGRectMake(self.view.frame.size.width/2 + 27.5f, self.view.frame.size.width/2 - 55, 110, 110); 
    self.selectPhotoButton.layer.cornerRadius = self.selectPhotoButton.frame.size.width/2.0f; 
    [self.selectPhotoButton setImage:[UIImage imageNamed:@"pick-photo-btn"] forState:UIControlStateNormal]; 
    [self.selectPhotoButton addTarget:self action:@selector(selectPhoto) forControlEvents:UIControlEventTouchUpInside]; 
    //[self.selectPhotoButton setBackgroundColor:[UIColor colorWithRed:0 green:255/255.0f blue:0 alpha:0.25f]]; 
    [self.view addSubview:self.selectPhotoButton]; 


    self.photoView        = [[UIImageView alloc] init]; 
    self.photoView.backgroundColor    = [UIColor colorWithRed:255.0f/255.0f green:000.0f/255.0f blue:000.0f/255.0f alpha:0.25f]; 
    self.photoView.frame      = CGRectMake(0, 0, 320, 320); 
    self.photoView.layer.cornerRadius   = self.photoView.frame.size.width/2; 
    self.photoView.layer.masksToBounds   = YES; 
    self.photoView.userInteractionEnabled  = YES; 
} 

#pragma mark - 
#pragma mark Button's Actions 
- (void)takePhotoFunction 
{ 
    self.picker      = [[UIImagePickerController alloc] init]; 
    self.picker.delegate   = self; 
    self.picker.allowsEditing  = YES; 
    self.picker.sourceType   = UIImagePickerControllerSourceTypeCamera; 
    self.picker.showsCameraControls = NO; 
    //self.picker.view.frame   = self.photoView.bounds; 
    self.picker.view.frame   = CGRectMake(0, -50, photoView.frame.size.width, photoView.frame.size.height + 50); 
    [self.photoView addSubview:self.picker.view]; 

    self.takePicture     = [UIButton buttonWithType:UIButtonTypeSystem]; 
    self.takePicture.frame    = CGRectMake(self.photoView.frame.size.width/2 - 35, self.photoView.frame.size.height - 70, 70, 70); 
    [self.takePicture addTarget:self action:@selector(takePhotoAction:) forControlEvents:UIControlEventTouchUpInside]; 
    [self.takePicture setBackgroundImage:[UIImage imageNamed:@"take-photo-action"] forState:UIControlStateNormal]; 
    [self.photoView addSubview:self.takePicture]; 

    self.switchCameraButton = [[UIButton alloc] init]; 
    self.switchCameraButton.frame    = CGRectMake(self.photoView.frame.size.width/2 - 35, self.photoView.frame.origin.y, 70, 70); 
    [self.switchCameraButton addTarget:self action:@selector(switchCamera:) forControlEvents:UIControlEventTouchUpInside]; 
    [self.switchCameraButton setBackgroundImage:[UIImage imageNamed:@"reverse-camera-btn"] forState:UIControlStateNormal]; 
    [self.photoView addSubview:self.switchCameraButton]; 


    [self.view addSubview:self.photoView]; 
    isFromAlbum = NO; 
} 

- (void)selectPhoto 
{ 
    self.picker = [[UIImagePickerController alloc] init]; 
    self.picker.delegate = self; 
    self.picker.allowsEditing = YES; 
    self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

    isFromAlbum = YES; 

    [self presentViewController:self.picker animated:YES completion:NULL]; 
} 

-(IBAction)takePhotoAction:(id)sender 
{ 
    [self.picker takePicture]; 
} 

-(IBAction)switchCamera:(id)sender 
{ 
    if (picker.cameraDevice == UIImagePickerControllerCameraDeviceFront) 
    { 
     picker.cameraDevice = UIImagePickerControllerCameraDeviceRear; 
    } 
    else if (picker.cameraDevice == UIImagePickerControllerCameraDeviceRear) 
    { 
     picker.cameraDevice = UIImagePickerControllerCameraDeviceFront; 
    } 
} 

- (UIImage*)rotateUIImage:(UIImage*)sourceImage 
{ 
    CGSize size = sourceImage.size; 
    UIGraphicsBeginImageContext(CGSizeMake(size.height, size.width)); 
    [[UIImage imageWithCGImage:[sourceImage CGImage] scale:1.0 orientation:UIImageOrientationDownMirrored] drawInRect:CGRectMake(0,0,size.height ,size.width)]; 
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    return newImage; 
} 

#pragma mark - 
#pragma mark PickerController Delegate Methods 
- (void)imagePickerController:(UIImagePickerController *)myPicker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    //NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; 
    UIImage *originalImage, *editedImage, *imageToSave; 

    // Handle a still image capture 
    //if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) 
    if (isFromAlbum == NO) 
    { 
     editedImage = (UIImage *) [info objectForKey: 
            UIImagePickerControllerEditedImage]; 
     originalImage = (UIImage *) [info objectForKey: 
            UIImagePickerControllerOriginalImage]; 

     if (editedImage) 
     { 
      imageToSave = editedImage; 
     } 
     else 
     { 
      imageToSave = originalImage; 
     } 

     // Save the new image (original or edited) to the Camera Roll 
     //UIImageWriteToSavedPhotosAlbum (imageToSave, nil, nil , nil); 
     [self.takePhotoButton removeFromSuperview]; 
     [self.switchCameraButton removeFromSuperview]; 
     [self.selectPhotoButton removeFromSuperview]; 
     [self.picker.view removeFromSuperview]; 
     [self.takePicture removeFromSuperview]; 


     CGFloat minimumSide = fminf(imageToSave.size.width, imageToSave.size.height); 
     CGFloat finalSquareSize = 640.; 

     //create new drawing context for right size 
     CGRect rect = CGRectMake(0, 0, finalSquareSize, finalSquareSize); 
     CGFloat scalingRatio = 640.0/minimumSide; 
     UIGraphicsBeginImageContext(rect.size); 

     //draw 
     [imageToSave drawInRect:CGRectMake((minimumSide - originalImage.size.width)*scalingRatio/2., (minimumSide - originalImage.size.height)*scalingRatio/2., originalImage.size.width*scalingRatio, originalImage.size.height*scalingRatio)]; 

     UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext(); 

     UIGraphicsEndImageContext(); 


//  if (picker.cameraDevice == UIImagePickerControllerCameraDeviceFront) 
//  { 
//   [self rotateUIImage:croppedImage]; 
//  } 


     //[self.photoView setImage:imageToSave]; 
     [self.photoView setImage:croppedImage]; 
    } 
    else 
    { 
     [self.takePhotoButton removeFromSuperview]; 
     [self.selectPhotoButton removeFromSuperview]; 
     UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; 
     [self.photoView setImage:chosenImage]; 
     [self.view addSubview:self.photoView]; 
     [myPicker dismissViewControllerAnimated:YES completion:NULL]; 
    } 
} 

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)myPicker 
{ 
    //[picker.view removeFromSuperview]; 
    [myPicker dismissViewControllerAnimated:YES completion:NULL]; 
} 

#pragma mark - 
#pragma mark NavigationController Methods 
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
{ 
    [[UIApplication sharedApplication] setStatusBarHidden:NO]; 
} 

@end 
관련 문제