I'm trying to save contents of an NSView as an image, but, only the image visible inside the scrollview is saved.
Here is the actual image loaded in the view: .
But this is how I'm able to save the image:
Is there any way to save the entire image in the NSView?
This is how I'm saving my NSView subclass:
- (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];
}
This method is in the View i want to save.
Use -[NSView cacheDisplayInRect:toBitmapImageRep:]
NSBitmapImageRep* rep = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
[self cacheDisplayInRect:self.bounds toBitmapImageRep:rep];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With