这里你需要做的是对你的窗口进行屏幕截图,一旦你得到屏幕截图你就会得到那张图片。但您需要根据您的要求进行更改。当你拍摄窗口的屏幕截图时,你也会看到导航栏和工具栏。因此,您需要拍摄一个屏幕快照,然后从中拍摄第二个屏幕快照以获得没有导航栏和工具栏的图像。
要保存图像,请访问以下网址:
以下是我所做的:
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
endPoint = [touch locationInView:self.IBImgView];
SPUserResizableView *spResizable = [[SPUserResizableView alloc] initWithFrame:CGRectMake(0,0,100,200)];
UIView *contentView = [[UIView alloc] initWithFrame:spResizable.frame];
[contentView setBackgroundColor:[UIColor clearColor]];
CAShapeLayer *lines = [CAShapeLayer layer];
lines.path = self.drawPath.CGPath;
lines.lineCap = kCALineCapSquare;
[self.drawPath removeAllPoints];
lines.bounds = CGPathGetBoundingBox(lines.path);
lines.strokeColor = [UIColor blackColor].CGColor;
lines.fillColor = [UIColor blackColor].CGColor; /*if you just want lines*/
lines.lineWidth = 3;
lines.position = CGPointMake(spResizable.frame.size.width/2.0f-10, spResizable.frame.size.height/2.0f-10);
lines.anchorPoint = CGPointMake(.5, .5);
[contentView.layer addSublayer:lines];
spResizable.contentView = contentView;
[spResizable hideEditingHandles];
[self.view addSubview:spResizable];
[self.view setNeedsDisplay];
}
保存图像
- (IBAction)btnSaveTapped:(id)sender {
[UIImagePNGRepresentation(self.IBImgView.image) writeToFile:[self saveDataInDirectory:@"Img1"] atomically:YES];
}
- (NSString *) saveDataInDirectory:(NSString *)strFileName {
NSString *strDocPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *strDirName;
NSFileManager *fileManager = [[NSFileManager alloc] init];
// Original Image
strDirName = [strDocPath stringByAppendingPathComponent:kDocOriginalImg];
if (![fileManager fileExistsAtPath:strDirName]) {
[fileManager createDirectoryAtPath:strDirName withIntermediateDirectories:NO attributes:nil error:nil];
}
strDirName = [[strDirName stringByAppendingPathComponent:strFileName] stringByAppendingPathExtension:@"png"];
return strDirName;
}
但请确保spResizable视图位于UIImageView之上。
Taking ScreenShot Programmatically
如果您想用相同的路径重新绘制图像,然后删除当前路径并绘制新路径,则可以使用
SPUserResizableView
但为此,您需要将数据存储在字典中进行编辑。
希望这将有助于解决您的问题。