Created
January 5, 2022 21:09
-
-
Save hjerpbakk/e485239e25a0e824afa0294e720998be to your computer and use it in GitHub Desktop.
Scale an image to fit using C#, Xamarin and SpriteKit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var image = SKSpriteNode.FromTexture(SKTexture.FromImageNamed("image-name")); | |
image.Position = new CGPoint(Frame.GetMidX(), Frame.GetMidY()); | |
var widthScaleFactor = device.DeviceSize.Width / image.Size.Width; | |
var heightScaleFactor = device.DeviceSize.Height / image.Size.Height; | |
var scaleFactor = widthScaleFactor < heightScaleFactor ? widthScaleFactor : heightScaleFactor; | |
image.SetScale(scaleFactor); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment