yue1liang1chuan
yue1liang1chuan
2013-03-13 08:56
采纳率: 69.8%
浏览 2.4k
已采纳

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

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

- (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]);
        }
    }];
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • ybh37
    咸清 2013-03-20 09:44
    已采纳

    截屏吧

            UIGraphicsBeginImageContextWithOptions(pageView.page.bounds.size, YES, zoomScale);
            [pageView.page.layer renderInContext:UIGraphicsGetCurrentContext()];
            UIImage *uiImage = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
    
    点赞 评论

相关推荐