Beispiel #1
0
        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 = new RectangleF();
                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
            }));
        }