在保存相片的時候將一些數據疊加到相片上,代碼如下:不知道有沒有簡單的方法實現?
- (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]);
}
}];
}
截屏吧
UIGraphicsBeginImageContextWithOptions(pageView.page.bounds.size, YES, zoomScale);
[pageView.page.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *uiImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();