我正在做一个项目,屏幕的特定部分必须保存为图像。
我创建了一个名为customView
. 我在这个视图中放置了一个图像视图和标签,并使用以下代码来捕获图像。
-(IBAction)saveButtonClicked
{
CGSize screenSize = [[UIScreen mainScreen] applicationFrame].size;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(nil, screenSize.width, screenSize.height, 8, 4*(int)screenSize.width, colorSpaceRef,
kCGImageAlphaPremultipliedLast);
CGContextTranslateCTM(ctx, 0.0, screenSize.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
[(CALayer*)self.view.layer renderInContext:ctx];
CGImageRef cgImage = CGBitmapContextCreateImage(ctx);
UIImage *image = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
CGContextRelease(ctx);
[UIImageJPEGRepresentation(image, 1.0) writeToFile:filePath atomically:NO];
}
文件路径是 /Users/mac/Library/Application Support/iPhone Simulator/3.2/Applications/388C6FB6-9D76-4507-9D3A-03D615BB63AD/Documents/savedImage.png。我filepath
使用以下代码创建
NSArray *documentsArray=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docPath=[documentsArray objectAtIndex:0];
filePath = [docPath stringByAppendingPathComponent:@"savedImage.png"];
谁能告诉我如何解决这个问题?