希望这将是一个重复的问题,但我真的陷入写入png数据块。有人可以帮助我如何从Objective-C中的数据中获取标题?以下是信息Section 4.7.2 , c part, Textual Information。
由于
答案 0 :(得分:0)
我认为没有必要关心png数据块,只需尝试下面的代码:
//load target image, then draw text on the target image
UIImage * image = [UIImage imageNamed:@"targetImage.png"];
NSString * text = @"Watermark!";
CGPoint startPoint = CGPointMake(20, 30);
UIFont *font = [UIFont boldSystemFontOfSize:12];
UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0,0,image.size.width,image.size.height)];
CGRect rect = CGRectMake(startPoint.x, startPoint.y, image.size.width, image.size.height);
[[UIColor whiteColor] set];
[text drawInRect:CGRectIntegral(rect) withFont:font];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Convert UIImage object into NSData (a wrapper for a stream of bytes) formatted according to PNG spec
NSData *imageData = UIImagePNGRepresentation(newImage);
//Save imageDate to disk as a png file
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *imageSubdirectory = [documentsDirectory stringByAppendingPathComponent:@"watermarkFolderName"];
NSString *filePath = [imageSubdirectory stringByAppendingPathComponent:@"watermark.png"];
[imageData writeToFile:filePath atomically:YES];