gpt4 book ai didi

iphone - 如何保存照片并在照片上叠加标签?

转载 作者:行者123 更新时间:2023-11-29 04:05:41 26 4
gpt4 key购买 nike

所以我想在拍摄照片时将数据叠加在照片上。这是我的代码。有没有更简单的方法在照片上叠加数据?

- (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]);
}
}];

最佳答案

刚刚测试了这个,它有效......

- (UIImage *)imageWithBackground:(UIImage *)background text:(NSString *)text textColor:(UIColor *)textColor {

UIImageView *imageView = [[UIImageView alloc] initWithImage:background];
UIView *composition = [[UIView alloc] initWithFrame:imageView.bounds];
[composition addSubview:imageView];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(/* where you want the label */)];
label.text = text;
label.backgroundColor = [UIColor clearColor];
label.textColor = textColor;
[composition addSubview:label];

UIGraphicsBeginImageContext(composition.bounds.size);
[composition.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *composedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return composedImage;
}

关于iphone - 如何保存照片并在照片上叠加标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15283091/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com