Alt*_*cho 13 cocoa objective-c
我正在尝试将NSView的内容保存为图像,但是,只保存了在scrollview中可见的图像.
以下是视图中加载的实际图像:
.
但这就是我能够保存图像的方式:
有没有办法在NSView中保存整个图像?
这就是我如何保存我的NSView子类:
- (void)save
{
[self lockFocus];
NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[self bounds]];
[self unlockFocus];
NSData* data = [rep representationUsingType:NSPNGFileType properties:nil];
NSString* string = NSHomeDirectory();
NSString* pth1 = [string stringByAppendingPathComponent:@"ttx.png"];
[data writeToFile:pth1 atomically:YES];
}
Run Code Online (Sandbox Code Playgroud)
此方法位于我要保存的视图中.
ham*_*ene 18
使用 -[NSView cacheDisplayInRect:toBitmapImageRep:]
NSBitmapImageRep* rep = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
[self cacheDisplayInRect:self.bounds toBitmapImageRep:rep];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3008 次 |
最近记录: |