-
-
Save anaisbetts/1775691 to your computer and use it in GitHub Desktop.
Sometimes, exporting images isn't easy
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
public class UIKitExportEnv : ExportEnv | |
{ | |
public UIKitExportEnv (string name, Model model) | |
: base (name, model) | |
{ | |
} | |
protected override void WriteTexture (ITexture texture, ExportedFile file) | |
{ | |
var width = texture.Width; | |
var height = texture.Height; | |
using (var imageContext = texture.CreateContext ()) | |
using (var image = imageContext.ToImage ()) | |
using (var renderContext = texture.CreateContextWithData (IntPtr.Zero)) { | |
renderContext.TranslateCTM (0, height); | |
renderContext.ScaleCTM (1, -1); | |
renderContext.DrawImage (new RectangleF (0, 0, width, height), image); | |
using (var render = renderContext.ToImage ()) | |
using (var uiImage = new UIImage (render)) | |
using (var data = uiImage.AsPNG ()) { | |
unsafe { | |
using (var s = new UnmanagedMemoryStream ((byte*)data.Bytes, data.Length)) { | |
s.CopyTo (file.Stream); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment