开发者社区 问答 正文

保存一张被标签覆盖的图片

在保存相片的时候将一些数据叠加到相片上,代码如下:不知道有没有简单的方法实现?

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info 
{         
    UIImage *cameraImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    UIImageView *imageViewToSave = [[UIImageView alloc] initWithImage:cameraImage];
    CGRect textFrame = CGRectMake(0, 0, imageViewToSave.frame.size.width-20, 325);
    UILabel *tempLabel = [[UILabel alloc] initWithFrame:textFrame];
    tempLabel.text = self.temperatureText.text;
    tempLabel.font = self.imageLabelFont;
    tempLabel.adjustsFontSizeToFitWidth = YES;
    tempLabel.textAlignment = NSTextAlignmentRight;
    tempLabel.textColor = self.tempGreen;
    tempLabel.backgroundColor = [UIColor clearColor];
    [imageViewToSave addSubview:tempLabel];

    UIGraphicsBeginImageContext(imageViewToSave.bounds.size);
    [imageViewToSave.layer renderInContext:UIGraphicsGetCurrentContext()];

    cameraImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    [self.library saveImage:cameraImage toAlbum:@"Node Therma" withCompletionBlock:^(NSError *error) 
    {
        if (error!=nil) 
        {
            NSLog(@"Big error: %@", [error description]);
        }
    }];
}

展开
收起
爵霸 2016-03-24 10:46:47 1957 分享 版权
1 条回答
写回答
取消 提交回答
  • 
     UIGraphicsBeginImageContextWithOptions(pageView.page.bounds.size, YES, zoomScale);
            [pageView.page.layer renderInContext:UIGraphicsGetCurrentContext()];
            UIImage *uiImage = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
    2019-07-17 19:12:13
    赞同 展开评论
问答地址: