保存到相机胶卷时是否可以为图像添加文本字符串?
例如拍摄照片并保存到相机胶卷:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image, nil,@selector(image:didFinishSavingWithError:contextInfo:), nil);
//something here to add @"my pre defined text"; to saved image
}
如果可能,我想在没有任何用户输入的情况下自动将预定义的文本添加到此已保存的图像中?
关于SO和Google关于我正在尝试做什么的常规搜索没有任何结果
答案 0 :(得分:1)
查看我的代码:
-(UIImage *)addText:(UIImage *)img text:(NSString *)text1
{
int w = img.size.width;
int h = img.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1);
char* text = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];
CGContextSelectFont(context, "Arial", 18, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBFillColor(context, 255, 255, 255, 2);
CGContextShowTextAtPoint(context, 10, 170, text, strlen(text));
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return [UIImage imageWithCGImage:imageMasked];
}
并改进:
- (IBAction)drawImage:(id)sender {
NSString *text1 = myTextField.text;
UIImage *updatedImg = [self addText:myImageView.image text:text1];
[myImageView setImage: updatedImg];
}
我希望这可以帮到你;)
thx for vote;)
答案 1 :(得分:0)