I've been working on a project that changes the desktop image, which I've been accomplishing like so:
[[NSWorkspace sharedWorkspace] setDesktopImageURL:fileURL forScreen:[NSScreen mainScreen] options:[NSDictionary dictionary] error:&error];
This works, but gives me no control over the scaling. I'd like to be able to choose scaling options programatically as you can in the UI (fill screen, fit to screen, stretch to fill screen, center, tile), but I can find no documentation explaining how to do so. Worse than that, calling the above method always resets the scaling to "fill screen".
Any assistance would be greatly appreciated. Thanks for your time and help!
You can set the NSWorkspaceDesktopImageScalingKey
in the option
parameter. Here's the possible values:
NSImageScaleProportionallyDown
If it is too large for the destination, scale the image down while preserving the aspect ratio.
NSImageScaleAxesIndependently
Scale each dimension to exactly fit destination. This setting does not preserve the aspect ratio of the image.
NSImageScaleNone
Do not scale the image.
NSImageScaleProportionallyUpOrDown
Scale the image to its maximum possible dimensions while both staying within the destination area and preserving its aspect ratio.
Declared in NSCell.h.