summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.MacOS/Extensions/NSImageExtensions.cs
blob: 09521731ccd60809c09b8baece6d01d3d5055698 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
		}
	}
}