I have an off-screen sequence of NSViews in a Cocoa application that are used to create PDFs for printing. Views are not in NSWindow or are visible in any way.
I would like to be able to create miniature images of this view, just like it would look in PDF format, but reduced to the size of a specific pixel (limited by width or height). It should be as fast as possible, so I would like to avoid rendering to PDF, and then convert to raster and scaling - I would like to go straight to the raster.
At the moment I am doing:
NSBitmapImageRep *bitmapImageRep = [pageView bitmapImageRepForCachingDisplayInRect:pageView.bounds]; [pageView cacheDisplayInRect:pageView.bounds toBitmapImageRep:bitmapImageRep]; NSImage *image = [[NSImage alloc] initWithSize:bitmapImageRep.size]; [image addRepresentation:bitmapImageRep];
This approach works well, but I can't decide how to apply scaling to the NSView before rendering bitmapImageRep. I want to avoid using scaleUnitSquareToSize
because, as far as I understand, this only changes the borders, not the NSView frame.
Any suggestions on the best way to do this?
source share