A game framework written with osu! in mind.
at master 1.4 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System.IO; 5using CoreGraphics; 6using Foundation; 7using osu.Framework.Graphics.Textures; 8using osu.Framework.IO.Stores; 9using SixLabors.ImageSharp; 10using UIKit; 11 12namespace osu.Framework.iOS.Graphics.Textures 13{ 14 public class IOSTextureLoaderStore : TextureLoaderStore 15 { 16 public IOSTextureLoaderStore(IResourceStore<byte[]> store) 17 : base(store) 18 { 19 } 20 21 protected override Image<TPixel> ImageFromStream<TPixel>(Stream stream) 22 { 23 using (var uiImage = UIImage.LoadFromData(NSData.FromStream(stream))) 24 { 25 int width = (int)uiImage.Size.Width; 26 int height = (int)uiImage.Size.Height; 27 28 // TODO: Use pool/memory when builds success with Xamarin. 29 // Probably at .NET Core 3.1 time frame. 30 var data = new byte[width * height * 4]; 31 using (CGBitmapContext textureContext = new CGBitmapContext(data, width, height, 8, width * 4, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedLast)) 32 textureContext.DrawImage(new CGRect(0, 0, width, height), uiImage.CGImage); 33 34 var image = Image.LoadPixelData<TPixel>(data, width, height); 35 36 return image; 37 } 38 } 39 } 40}