IOS在cameraRoll中将图像保存为圆形

IOS在cameraRoll中将图像保存为圆形,ios,objective-c,Ios,Objective C,我想将图像作为循环图像保存到iOS中的相册中。我试图用圆形遮罩图像,它在图像视图中运行良好,但当我保存同一图像时,它会被保存为原始图像 这是我的密码: @implementation ViewController @synthesize imageview, photo; - (void)viewDidLoad { [super viewDidLoad]; self.imageview.layer.masksToBounds = YES; self.imageview.layer.co

我想将图像作为循环图像保存到iOS中的相册中。我试图用圆形遮罩图像,它在图像视图中运行良好,但当我保存同一图像时,它会被保存为原始图像

这是我的密码:

@implementation ViewController

@synthesize imageview, photo;


- (void)viewDidLoad
{
[super viewDidLoad];


self.imageview.layer.masksToBounds = YES;
self.imageview.layer.cornerRadius = imageview.bounds.size.width/2;
self.imageview.layer.borderWidth = 1.0;
self.imageview.layer.borderColor =[UIColor colorWithRed:13/255 green:70/255 blue:131/255 alpha:1.0].CGColor;}



-(IBAction)takephoto:(id)sender{
picker1 = [[UIImagePickerController alloc]init];
picker1.delegate = self;

[picker1 setSourceType:(UIImagePickerControllerSourceTypeCamera)];
[self presentViewController:picker1 animated:YES completion:NULL];

}

-(IBAction)chooseExisting:(id)sender{
picker2 = [[UIImagePickerController alloc]init];
picker2.delegate = self;

[picker2 setSourceType:(UIImagePickerControllerSourceTypePhotoLibrary)];
[self presentViewController:picker2 animated:YES completion:NULL];}

 - (IBAction)save:(id)sender {



//NSString *shareText = @"download my add with the follow up link";for textwrking.

NSArray *itemsToShare =@[imageview.image];

UIActivityViewController *activityVC =[[UIActivityViewController alloc]initWithActivityItems:itemsToShare applicationActivities:nil];

activityVC.excludedActivityTypes =@[UIActivityTypePostToFacebook /* this is like excuding activities like fb,twitterand all  whtever we login on ios, we can use this code  */];

[self presentViewController:activityVC animated:YES completion:nil];}

  -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
photo=[info objectForKey:UIImagePickerControllerOriginalImage];
[imageview setImage:photo];
[self dismissViewControllerAnimated:YES completion:NULL];}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:NULL];}

`

在不使用imageview的情况下尝试此解决方案

- (UIImage *)imageWithRoundedCornersSize:(float)cornerRadius usingImage:(UIImage *)original
{
    CGRect frame = CGRectMake(0, 0, original.size.width, original.size.height);

    // Begin a new image that will be the new image with the rounded corners
    // (here with the size of an UIImageView)
    UIGraphicsBeginImageContextWithOptions(original.size, NO, 1.0);

    // Add a clip before drawing anything, in the shape of an rounded rect
    [[UIBezierPath bezierPathWithRoundedRect:frame
                                cornerRadius:cornerRadius] addClip];
    // Draw your image
    [original drawInRect:frame];

    // Get the image, here setting the UIImageView image
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    // Lets forget about that we were drawing
    UIGraphicsEndImageContext();

    return image;
}
- (IBAction)share:(id)sender {

    //NSString *shareText = @"download my add with the follow up link";for textwrking.

    NSArray *itemsToShare =@[[self imageWithRoundedCornersSize:self.imageview.image.size.width*2 usingImage:self.imageview.image]];

    UIActivityViewController *activityVC =[[UIActivityViewController alloc]initWithActivityItems:itemsToShare applicationActivities:nil];

    activityVC.excludedActivityTypes =@[UIActivityTypePostToFacebook /* this is like excuding activities like fb,twitterand all  whtever we login on ios, we can use this code  */];

    [self presentViewController:activityVC animated:YES completion:nil];
}

仅供参考,此图像舍入功能适用于方形图像,但不适用于矩形图像。对于矩形图像,您必须以圆形方式裁剪图像的一部分并绘制新图像。

尝试过此图像,但仍将其保存为普通图像,请有人帮助我直到其不起作用,我可以发送我的文件,您可以提供您的电子邮件id吗请查看一下它将很有帮助。、。,,satheesh4590@gmail.comi刚刚邮寄了我的文件,请检查一下,让我知道检查一下你的邮件我已经回复了