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
#if UNIFIED
                var rect = new CoreGraphics.CGRect();
#else
                var rect = new RectangleF();
#endif

                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
            }));
        }
Beispiel #2
0
        public static System.IO.Stream AsJpegStream(this PImage image, int quality = 80)
        {
#if __IOS__ || __TVOS__
            return(image.AsJPEG(quality / 100f).AsStream());
#elif __MACOS__
            // todo: jpeg quality?
            var imageRep = new NSBitmapImageRep(image.AsTiff());
            return(imageRep.RepresentationUsingTypeProperties(NSBitmapImageFileType.Jpeg)
                   .AsStream());
#endif
        }