2012-01-19 19 views
1

私は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

Methinksが、これは重複している円形に画像の一部をトリミングすることを教えてください。この質問には優れた回答があり、他の記事へのリンクはHow to crop UIImage on oval shape or circle shape?

です。これについては、簡単な方法があります。 cornerRadiusが明白なCALayer。しかしもっと重要なのは、CGImageCreateWithMaskというメソッドが存在することです。これは、円や他の図形までのより広いスペクトルに適用できます。画像がJPEGの場合、JPEGにはアルファチャンネルがないため、CGImageCreateWithMaskは黒の背景を返します。

+1

重複している場合は、それに答えるのではなく、コメントする必要があります。 – Sarah

+0

リンクの回答の1つを編集して、すべての人にとってもう少し便利で受け入れやすいものにする必要がありますか? – CodaFi

+0

より良い今今 – Sarah

2

クォーツコアフレームワークを使用すると、本当にクールな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

関連する問題