Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何保存覆盖有标签的照片?_Iphone_Ios_Objective C_Ipad_Ios5 - Fatal编程技术网

Iphone 如何保存覆盖有标签的照片?

Iphone 如何保存覆盖有标签的照片?,iphone,ios,objective-c,ipad,ios5,Iphone,Ios,Objective C,Ipad,Ios5,所以,我有数据,我想覆盖在一张照片时,它是采取。这是我的密码。有没有更简单的方法在照片上覆盖数据 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *cameraImage = [info objectForKey:UIImagePickerControllerOrigi

所以,我有数据,我想覆盖在一张照片时,它是采取。这是我的密码。有没有更简单的方法在照片上覆盖数据

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

与我的代码相比,您的代码似乎还可以,但请尝试使用新的局部变量 获取屏幕截图时,如下所示:

UIImage *cameraImage2 = UIGraphicsGetImageFromCurrentImageContext();
然后保存cameraImage2

还要确保self.tempGreen不是ClearColor