Exemplo n.º 1
0
        public void FromData_BadITU()
        {
            using (NSMutableData destData = new NSMutableData()) {
#if XAMCORE_2_0 // FromData => Create
                Assert.Null(CGImageDestination.Create(destData, BadUti, 1), "FromData-1");
                Assert.Null(CGImageDestination.Create(destData, BadUti, 1, new CGImageDestinationOptions()), "FromData-2");
#else
                Assert.Null(CGImageDestination.FromData(destData, BadUti, 1), "FromData-1");
                Assert.Null(CGImageDestination.FromData(destData, BadUti, 1, new CGImageDestinationOptions()), "FromData-2");
#endif
            }
        }
Exemplo n.º 2
0
        public void AddImage()
        {
            string file = Path.Combine(NSBundle.MainBundle.ResourcePath, "basn3p08.png");

            using (NSMutableData destData = new NSMutableData())
                using (var uiimg = UIImage.FromFile(file))
                    using (var img = uiimg.CGImage)
#if XAMCORE_2_0 // FromData => Create
                        using (var id = CGImageDestination.Create(destData, GoodUti, 1)) {
#else
                        using (var id = CGImageDestination.FromData(destData, GoodUti, 1)) {
#endif
                            id.AddImage(img, (NSDictionary)null);
                        }
        }
Exemplo n.º 3
0
        public void CopyImageSource()
        {
            TestRuntime.AssertXcodeVersion(5, 0);

            using (NSData data = NSData.FromFile("xamarin2.png"))
                using (var source = CGImageSource.FromData(data))
                    using (NSMutableData destData = new NSMutableData())
#if XAMCORE_2_0 // FromData => Create
                        using (var id = CGImageDestination.Create(destData, GoodUti, 1)) {
#else
                        using (var id = CGImageDestination.FromData(destData, GoodUti, 1)) {
#endif
                            NSError err;
                            // testing that null is allowed (no crash) so the fact that is return false and an error does not matter
                            Assert.False(id.CopyImageSource(source, (NSDictionary)null, out err), "CopyImageSource");
                            Assert.NotNull(err, "NSError");
                        }
        }
Exemplo n.º 4
0
        public void AddImageAndMetadata()
        {
            TestRuntime.AssertXcodeVersion(5, 0);

            string file = Path.Combine(NSBundle.MainBundle.ResourcePath, "basn3p08.png");

            using (NSMutableData destData = new NSMutableData())
                using (var uiimg = UIImage.FromFile(file))
                    using (var img = uiimg.CGImage)
#if XAMCORE_2_0 // FromData => Create
                        using (var id = CGImageDestination.Create(destData, GoodUti, 1))
#else
                        using (var id = CGImageDestination.FromData(destData, GoodUti, 1))
#endif
                            using (var mutable = new CGMutableImageMetadata()) {
                                id.AddImageAndMetadata(img, mutable, (NSDictionary)null);
                            }
        }
Exemplo n.º 5
0
        public void FromData_GoodITU()
        {
            using (NSMutableData destData = new NSMutableData()) {
#if XAMCORE_2_0 // FromData => Create
                using (var id = CGImageDestination.Create(destData, GoodUti, 1)) {
#else
                using (var id = CGImageDestination.FromData(destData, GoodUti, 1)) {
#endif
                    Assert.That(id.Handle, Is.Not.EqualTo(IntPtr.Zero), "handle-1");
                }
#if XAMCORE_2_0 // FromData => Create
                using (var id = CGImageDestination.Create(destData, GoodUti, 1, new CGImageDestinationOptions())) {
#else
                using (var id = CGImageDestination.FromData(destData, GoodUti, 1, new CGImageDestinationOptions())) {
#endif
                    Assert.That(id.Handle, Is.Not.EqualTo(IntPtr.Zero), "handle-2");
                }
            }
        }
Exemplo n.º 6
0
        public new void Save(Stream stream, ImageFormat format)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            using (var imageData = new NSMutableData())
            {
                                #if !XAMARINMAC
                using (var dest = CGImageDestination.FromData(imageData, GetTypeIdentifier(format), frameCount))
                                #else
                using (var dest = CGImageDestination.Create(imageData, GetTypeIdentifier(format), frameCount))
                                #endif
                    Save(dest);

                using (var ms = imageData.AsStream())
                    ms.CopyTo(stream);
            }
        }