summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.MacOS/Extensions/NSImageExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.MacOS/Extensions/NSImageExtensions.cs')
-rw-r--r--Xamarin.Forms.Platform.MacOS/Extensions/NSImageExtensions.cs22
1 files changed, 22 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.MacOS/Extensions/NSImageExtensions.cs b/Xamarin.Forms.Platform.MacOS/Extensions/NSImageExtensions.cs
new file mode 100644
index 0000000..0952173
--- /dev/null
+++ b/Xamarin.Forms.Platform.MacOS/Extensions/NSImageExtensions.cs
@@ -0,0 +1,22 @@
+´╗┐using AppKit;
+
+namespace Xamarin.Forms.Platform.MacOS
+{
+ public static class NSImageExtensions
+ {
+ public static NSImage ResizeTo(this NSImage self, CoreGraphics.CGSize newSize)
+ {
+ if (self == null)
+ return null;
+ self.ResizingMode = NSImageResizingMode.Stretch;
+ var resizedImage = new NSImage(newSize);
+ resizedImage.LockFocus();
+ self.Size = newSize;
+ NSGraphicsContext.CurrentContext.ImageInterpolation = NSImageInterpolation.High;
+ self.Draw(CoreGraphics.CGPoint.Empty, new CoreGraphics.CGRect(0, 0, newSize.Width, newSize.Height),
+ NSCompositingOperation.Copy, 1.0f);
+ resizedImage.UnlockFocus();
+ return resizedImage;
+ }
+ }
+} \ No newline at end of file