美文网首页
将图片写入相册的方法代码

将图片写入相册的方法代码

作者: lixiaoshuai | 来源:发表于2016-05-13 16:56 被阅读34次

    //保存到相册

    UIGraphicsBeginImageContext(self.captureImv.bounds.size);

    [self.captureImv.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *temp = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(temp, nil, nil, nil);

    将图片存储在本地的方法

    NSData *imageData = UIImageJPEGRepresentation(self.completeImage, 1);

    NSLog(@"截取后图片为:%uldKB",[imageData length]/1000);

    //保存到沙盒

    [imageData writeToFile:self.imageFilePath atomically:YES];

    NSLog(@"图片在这里-->%@",self.imageFilePath);

    截取固定区域图片的方法

    //截取全屏

    UIGraphicsBeginImageContext(CGSizeMake(k_width, k_height));

    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    //截取所需区域

    CGRect captureRect = CGRectMake(capture_x,capture_y,capture_width,capture_width);

    CGImageRef sourceImageRef = [image CGImage];

    CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, captureRect);

    UIImage *newImage = [UIImage imageWithCGImage:newImageRef];

    self.captureImv.image = newImage;

    相关文章

      网友评论

          本文标题:将图片写入相册的方法代码

          本文链接:https://www.haomeiwen.com/subject/jvhmrttx.html