2012-01-19 11 views
1

하나의 .jpg 이미지를 표시하는 응용 프로그램을 만들고 있습니다. 나는 원형의 이미지 부분을 자르고 싶다. 이 문제를 해결하도록 도와주세요.원형 모양의 자르기 이미지

image = [UIImage imageNamed:@"images2.jpg"]; 
imageView = [[UIImageView alloc] initWithImage:image]; 

CGSize size = [image size]; 

[imageView setFrame:CGRectMake(0, 0, size.width, size.height)]; 
[[self view] addSubview:imageView]; 
[imageView release];  

+0

중복 가능성을 확인 [타원형 또는 원형 모양에있는 UIImage를 자르려면 어떻게?] (http://stackoverflow.com/questions/6530573/how-to-crop -uiimage-on-oval-shape-or-circle-shape) –

답변

2

...이라고 생각되다는이 중복 원형 이미지의 일부를 잘라 내게 알려주십시오. 이 질문에 대한 훌륭한 대답과 다른 기사에 대한 링크가 있습니다. How to crop UIImage on oval shape or circle shape?

편집 :이 문제를 해결하는 몇 가지 쉬운 방법이 있습니다. cornerRadius가 명백한 CALayer입니다. 그러나 더 중요한 것은 CGImageCreateWithMask : 원 및 다른 모양까지의 더 넓은 범위의 스펙트럼에 적용 할 수있는 메서드가 있다는 것입니다. 이미지가 JPEG 인 경우 JPEG에 알파 채널이 없으므로 CGImageCreateWithMask는 검정색 배경을 반환합니다.

+1

중복 된 경우 대답하지 말고 주석 처리해야합니다. – Sarah

+0

링크에있는 답변 중 하나를 편집하여 모두에게 좀 더 편리하고 수용 가능하도록해야합니까? – CodaFi

+0

더 나은 지금은 – Sarah

2

Quartz Core 프레임 워크를 사용하면 할 수 있습니다. 정말 멋진 Apis가 있습니다. thisRoundedImageView 예를 확인하십시오.

+1

이 링크 던지고 404 : ( – Femina

+0

그것을 확인하십시오 : - https://github.com/kidsid49/RoundedImageView – kidsid49

0
 You can use RSKImageCropper for crop the image in circular shape. I am implemented the fallowing code to crop the image in circular shape with the help of RSKImageCropper. 

     1. Install the pod RSKImageCropper. 
     2. #import <RSKImageCropper/RSKImageCropper.h> in your viewcontroller 
     3. Add delegate to your interface i.e. RSKImageCropViewControllerDelegate 
     4. Implement the fallowing code in **didFinishPickingMediaWithInfo** delegate. 

    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
     { 
      UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage]; 
       [picker dismissViewControllerAnimated:YES completion: 
       ^{ 
       RSKImageCropViewController *imageCropVC = [[RSKImageCropViewController alloc] initWithImage:originalImage]; 
        imageCropVC.avoidEmptySpaceAroundImage = YES; 
       imageCropVC.delegate = self; 
        [self presentViewController:imageCropVC animated:NO completion:nil]; 
       }]; 
     } 

    5. Now implement the delegate of RSKImageCropper. 

    - (void)imageCropViewControllerDidCancelCrop:(RSKImageCropViewController *)controller 
    { 
     [controller dismissViewControllerAnimated:NO completion:nil]; 
    } 

    // The original image has been cropped. 
    - (void)imageCropViewController:(RSKImageCropViewController *)controller 
         didCropImage:(UIImage *)croppedImage 
         usingCropRect:(CGRect)cropRect 
    { 
     self.imgVIew.image = croppedImage; 
     [self.navigationController popViewControllerAnimated:YES]; 
    } 

    // The original image has been cropped. Additionally provides a rotation angle used to produce image. 
    - (void)imageCropViewController:(RSKImageCropViewController *)controller 
         didCropImage:(UIImage *)croppedImage 
         usingCropRect:(CGRect)cropRect 
         rotationAngle:(CGFloat)rotationAngle 
    { 
     self.imgVIew.image = croppedImage; 
     [controller dismissViewControllerAnimated:NO completion:nil]; 
    } 

더 많은 정보의 https://github.com/ruslanskorb/RSKImageCropper