public static System.IO.Stream AsPngStream(this PImage image) { #if __IOS__ || __TVOS__ return(image.AsPNG()?.AsStream()); #elif __MACOS__ var imageRep = new NSBitmapImageRep(image.AsTiff()); return(imageRep.RepresentationUsingTypeProperties(NSBitmapImageFileType.Png) .AsStream()); #endif }
/// <inheritdoc /> public Task Save(CompressedBitmapFormat format, float quality, Stream target) { return(Task.Run(() => { #if UIKIT var data = format == CompressedBitmapFormat.Jpeg ? _inner.AsJPEG((float)quality) : _inner.AsPNG(); data.AsStream().CopyTo(target); #else var rect = CGRect.Empty; var cgImage = _inner.AsCGImage(ref rect, null, null); var imageRep = new NSBitmapImageRep(cgImage); var props = format == CompressedBitmapFormat.Png ? new NSDictionary() : new NSDictionary(new NSNumber(quality), new NSString("NSImageCompressionFactor")); var type = format == CompressedBitmapFormat.Png ? NSBitmapImageFileType.Png : NSBitmapImageFileType.Jpeg; var outData = imageRep.RepresentationUsingTypeProperties(type, props); outData.AsStream().CopyTo(target); #endif })); }