Example #1
0
        public void FromUrlTest()
        {
#if MONOMAC
            using (var img = CGImageSource.FromUrl(fileUrl)) {
#else
            using (var img = CGImageSource.FromUrl(NSUrl.FromFilename(filename))) {
#endif
                Assert.NotNull(img, "#a1");
            }

#if MONOMAC
            using (var img = CGImageSource.FromUrl(fileUrl, new CGImageOptions())) {
#else
            using (var img = CGImageSource.FromUrl(NSUrl.FromFilename(filename), new CGImageOptions())) {
#endif
                Assert.NotNull(img, "#b1");
            }

#if MONOMAC
            using (var img = CGImageSource.FromUrl(fileUrl, null)) {
#else
            using (var img = CGImageSource.FromUrl(NSUrl.FromFilename(filename), null)) {
#endif
                Assert.NotNull(img, "#c1");
            }
        }
Example #2
0
        public void CopyProperties()
        {
            // what we had to answer with 5.2 for http://stackoverflow.com/q/10753108/220643
            IntPtr lib = Dlfcn.dlopen(Constants.ImageIOLibrary, 0);

            try {
                NSString kCGImageSourceShouldCache   = Dlfcn.GetStringConstant(lib, "kCGImageSourceShouldCache");
                NSString kCGImagePropertyPixelWidth  = Dlfcn.GetStringConstant(lib, "kCGImagePropertyPixelWidth");
                NSString kCGImagePropertyPixelHeight = Dlfcn.GetStringConstant(lib, "kCGImagePropertyPixelHeight");

#if MONOMAC
                using (var imageSource = CGImageSource.FromUrl(fileUrl)) {
#else
                using (var imageSource = CGImageSource.FromUrl(NSUrl.FromFilename(filename))) {
#endif
                    using (var dict = new NSMutableDictionary()) {
                        dict [kCGImageSourceShouldCache] = NSNumber.FromBoolean(false);
                        using (var props = imageSource.CopyProperties(dict)) {
                            Assert.Null(props.ValueForKey(kCGImagePropertyPixelWidth), "kCGImagePropertyPixelWidth");
                            Assert.Null(props.ValueForKey(kCGImagePropertyPixelHeight), "kCGImagePropertyPixelHeight");
                            NSNumber n = (NSNumber)props ["FileSize"];
                            // image is "optimized" for devices (and a lot bigger at 10351 bytes ;-)
                            Assert.That((int)n, Is.AtLeast(7318), "FileSize");
                        }
                    }
                }
            }
            finally {
                Dlfcn.dlclose(lib);
            }
        }
        public Size GetImageSize(string imagePath)
        {
            try
            {
                NSUrl         url           = new NSUrl(path: imagePath, isDir: false);
                CGImageSource myImageSource = CGImageSource.FromUrl(url, null);
                var           ns            = new NSDictionary();

                //Dimensions
                NSObject width;
                NSObject height;

                using (NSDictionary imageProperties = myImageSource.CopyProperties(ns, 0))
                {
                    var tiff = imageProperties.ObjectForKey(CGImageProperties.TIFFDictionary) as NSDictionary;
                    width  = imageProperties[CGImageProperties.PixelWidth];
                    height = imageProperties[CGImageProperties.PixelHeight];
                }

                return(new Size(Convert.ToInt32(height.ToString()),
                                Convert.ToInt32(width.ToString())));
            }
            catch
            {
                return(Size.Empty);
            }
        }
Example #4
0
        public void GetProperties()
        {
#if MONOMAC
            using (var imageSource = CGImageSource.FromUrl(fileUrl)) {
#else
            using (var imageSource = CGImageSource.FromUrl(NSUrl.FromFilename(filename))) {
#endif
                CGImageOptions options = new CGImageOptions()
                {
                    ShouldCache = false
                };

                var props = imageSource.GetProperties(options);
                Assert.Null(props.PixelWidth, "PixelHeight-0");
                Assert.Null(props.PixelHeight, "PixelWidth-0");
                // image is "optimized" for devices (and a lot bigger at 10351 bytes ;-)
                Assert.That(props.FileSize, Is.AtLeast(7318), "FileSize");

                props = imageSource.GetProperties(0, options);
                Assert.AreEqual(57, props.PixelWidth, "PixelHeight");
                Assert.AreEqual(57, props.PixelHeight, "PixelWidth");
                Assert.AreEqual(CGImageColorModel.RGB, props.ColorModel, "ColorModel");
                Assert.AreEqual(8, props.Depth, "Depth");
            }
        }
Example #5
0
        /// <summary>
        /// Extract a DateTime object from a NSUrl object
        /// </summary>
        /// <param name="url">The url of the file</param>
        /// <returns>
        /// 1. The current date as a Nullable<DateTime> object IF url == null
        /// 2. The date (as a Nullable<DateTime> object) that exists within the file's metadata (pointed to by url) IFF the EXIF data exists
        /// 3. Null if the date cannot be found within the file's metadata
        /// </returns>
        private DateTime?GetDate(NSUrl url)
        {
            DateTime dateTaken;

            // If the provided url is null
            // NOTE: This case will happen if we import from camera
            if (url == null)
            {
                dateTaken = DateTime.Now;
                return(dateTaken);
            }

            CGImageSource source     = CGImageSource.FromUrl(url);
            NSDictionary  ns         = new NSDictionary();
            NSDictionary  properties = source.CopyProperties(ns, 0);

            NSDictionary exifDict = properties?.ObjectForKey(ImageIO.CGImageProperties.ExifDictionary) as NSDictionary;

            if (exifDict != null)
            {
                NSString date = exifDict[ImageIO.CGImageProperties.ExifDateTimeOriginal] as NSString;

                if (!string.IsNullOrEmpty(date) &&
                    DateTime.TryParseExact(date, "yyyy:MM:dd HH:mm:ss", CultureInfo.CurrentCulture, DateTimeStyles.None, out dateTaken))
                {
                    return(dateTaken);
                }
            }

            return(null);
        }
Example #6
0
        //http://chadkuehn.com/read-metadata-from-photos-in-c/
        private DateTime?ExtractDateTimeTaken(string path)
        {
            DateTime?     dt              = null;
            NSUrl         url             = new NSUrl(path: path, isDir: false);
            CGImageSource myImageSource   = CGImageSource.FromUrl(url, null);
            var           ns              = new NSDictionary();
            var           imageProperties = myImageSource.CopyProperties(ns, 0);

            var tiff = imageProperties.ObjectForKey(CGImageProperties.TIFFDictionary) as NSDictionary;
            var exif = imageProperties.ObjectForKey(CGImageProperties.ExifDictionary) as NSDictionary;

            //DateTaken
            var dtstr = (exif[CGImageProperties.ExifDateTimeOriginal]).ToString();

            if (string.IsNullOrEmpty(dtstr))
            {
                dtstr = (tiff[CGImageProperties.TIFFDateTime]).ToString();
            }
            if (!string.IsNullOrEmpty(dtstr))
            {
                dt = DateTime.ParseExact(dtstr, "yyyy:MM:dd HH:mm:ss", CultureInfo.InvariantCulture);
            }

            return(dt);
        }
Example #7
0
        public Bitmap(string filename, bool useIcm)
        {
            // TODO: Implement useIcm

            if (filename == null)
            {
                throw new ArgumentNullException("Value can not be null");
            }

            try
            {
                imageSource = CGImageSource.FromUrl(NSUrl.FromFilename(filename));
                if (imageSource == null)
                {
                    throw new FileNotFoundException("File {0} not found.", filename);
                }

                InitializeImageFrame(0);
#if DEBUG
                Tag = filename;
#endif
            }
            catch (Exception)
            {
                throw new FileNotFoundException("File {0} not found.", filename);
            }
        }
Example #8
0
        public void RemoveCache()
        {
            TestRuntime.AssertXcodeVersion(5, 0);

            using (var imageSource = CGImageSource.FromUrl(NSUrl.FromFilename(filename))) {
                imageSource.RemoveCache(0);
            }
        }
Example #9
0
 public void CreateThumbnailTest()
 {
     using (var imgsrc = CGImageSource.FromUrl(NSUrl.FromFilename(filename))) {
         using (var img = imgsrc.CreateThumbnail(0, null)) {
             Assert.NotNull(img, "#a1");
         }
         using (var img = imgsrc.CreateThumbnail(0, new CGImageThumbnailOptions())) {
             Assert.NotNull(img, "#b1");
         }
     }
 }
 public void CreateImageTest()
 {
     using (var imgsrc = CGImageSource.FromUrl(fileUrl)) {
         using (var img = imgsrc.CreateImage(0, null)) {
             Assert.NotNull(img, "#a1");
         }
         using (var img = imgsrc.CreateImage(0, new CGImageOptions())) {
             Assert.NotNull(img, "#b1");
         }
     }
 }
Example #11
0
        public void RemoveCache()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("Only on iOS7+");
            }

            using (var imageSource = CGImageSource.FromUrl(NSUrl.FromFilename(filename))) {
                imageSource.RemoveCache(0);
            }
        }
Example #12
0
        public object GetImageFromUri(FileUri imageUri, int targetWidth, int targetHeight, int rotation)
        {
            using (Stream stream = GetFileSystem().OpenFile(imageUri, UniversalFileMode.Open, UniversalFileAccess.Read, UniversalFileShare.Read))
            {
                CGImageSource source = CGImageSource.FromUrl(imageUri.ToNSUrl());

                CGImageOptions options = new CGImageOptions();
                options.ShouldCache = false;

                var props = source.CopyProperties(options, 0);

                int imageWidth  = ((NSNumber)props["PixelWidth"]).Int32Value;
                int imageHeight = ((NSNumber)props["PixelHeight"]).Int32Value;

                int scale = 1;
                while (imageWidth / scale / 2 >= (nfloat)targetWidth &&
                       imageHeight / scale / 2 >= (nfloat)targetHeight)
                {
                    scale *= 2;
                }

                stream.Seek(0, SeekOrigin.Begin);
                UIImage image = UIImage.LoadFromData(NSData.FromUrl(imageUri.ToNSUrl()), scale);

                if (rotation != 0)
                {
                    float radians = rotation * (float)Math.PI / 180f;

                    CGRect            imageFrame = new CGRect(0, 0, image.Size.Width, image.Size.Height);
                    CGAffineTransform t          = CGAffineTransform.MakeRotation(radians);
                    imageFrame = t.TransformRect(imageFrame);

                    CGSize rotatedSize = new CGSize(imageFrame.Width, imageFrame.Height);

                    UIGraphics.BeginImageContext(rotatedSize);

                    using (CGContext context = UIGraphics.GetCurrentContext())
                    {
                        context.TranslateCTM(rotatedSize.Width / 2, rotatedSize.Height / 2);
                        context.RotateCTM(-radians);
                        context.ScaleCTM(1.0f, -1.0f);
                        image.Draw(new CGRect(-image.Size.Width / 2, -image.Size.Height / 2, image.Size.Width, image.Size.Height));

                        image = UIGraphics.GetImageFromCurrentImageContext();
                    }

                    UIGraphics.EndImageContext();
                }

                return(image);
            }
        }
Example #13
0
 public ImageSize ImageSizeIos(string localPath)
 {
     using (var src = CGImageSource.FromUrl(NSUrl.FromFilename(localPath)))
     {
         CGImageOptions options = new CGImageOptions()
         {
             ShouldCache = false
         };
         // do not forget the '0' image index or you won't get what you're looking for!
         var p = src.GetProperties(0, options);
         return(new ImageSize((int)p.PixelWidth, (int)p.PixelHeight));
     }
 }
Example #14
0
        public void FromUrlTest()
        {
            using (var img = CGImageSource.FromUrl(NSUrl.FromFilename(filename))) {
                Assert.NotNull(img, "#a1");
            }

            using (var img = CGImageSource.FromUrl(NSUrl.FromFilename(filename), new CGImageOptions())) {
                Assert.NotNull(img, "#b1");
            }

            using (var img = CGImageSource.FromUrl(NSUrl.FromFilename(filename), null)) {
                Assert.NotNull(img, "#c1");
            }
        }
Example #15
0
        public void CopyMetadata()
        {
            TestRuntime.AssertXcodeVersion(5, 0);

            using (var imageSource = CGImageSource.FromUrl(NSUrl.FromFilename(filename))) {
                CGImageOptions options = new CGImageOptions()
                {
                    ShouldCacheImmediately = true
                };
                using (CGImageMetadata metadata = imageSource.CopyMetadata(0, options)) {
                    Console.WriteLine();
                }
            }
        }
Example #16
0
        static public FormsCAKeyFrameAnimation CreateAnimationFromFileImageSource(FileImageSource imageSource)
        {
            FormsCAKeyFrameAnimation animation = null;
            string file = imageSource?.File;

            if (!string.IsNullOrEmpty(file))
            {
                using (var parsedImageSource = CGImageSource.FromUrl(NSUrl.CreateFileUrl(file, null)))
                {
                    animation = ImageAnimationHelper.CreateAnimationFromCGImageSource(parsedImageSource);
                }
            }

            return(animation);
        }
Example #17
0
        public void CreateImageTest()
        {
#if MONOMAC
            using (var imgsrc = CGImageSource.FromUrl(fileUrl)) {
#else
            using (var imgsrc = CGImageSource.FromUrl(NSUrl.FromFilename(filename))) {
#endif
                using (var img = imgsrc.CreateImage(0, null)) {
                    Assert.NotNull(img, "#a1");
                }
                using (var img = imgsrc.CreateImage(0, new CGImageOptions())) {
                    Assert.NotNull(img, "#b1");
                }
            }
        }
Example #18
0
        public void CopyMetadata()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("Only on iOS7+");
            }

            using (var imageSource = CGImageSource.FromUrl(NSUrl.FromFilename(filename))) {
                CGImageOptions options = new CGImageOptions()
                {
                    ShouldCacheImmediately = true
                };
                using (CGImageMetadata metadata = imageSource.CopyMetadata(0, options)) {
                    Console.WriteLine();
                }
            }
        }
        public UIImage Generate(CGSize size)
        {
            try
            {
                var imageSource = CGImageSource.FromUrl(Url);

                var thumbnail = imageSource.CreateThumbnail(0,
                                                            new CGImageThumbnailOptions
                {
                    MaxPixelSize = (int)(Math.Max(size.Width, size.Height) * UIScreen.MainScreen.Scale),
                    CreateThumbnailFromImageIfAbsent = true
                });
                return(UIImage.FromImage(thumbnail));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Example #20
0
        public void CreateThumbnailTest()
        {
            using (var imgsrc = CGImageSource.FromUrl(fileUrl)) {
                using (var img = imgsrc.CreateThumbnail(0, null)) {
#if NET
                    Assert.Null(img, "#a1");
#else
                    Assert.NotNull(img, "#a1");
                    Assert.AreEqual(IntPtr.Zero, img.Handle, "#a2");
#endif
                }
                using (var img = imgsrc.CreateThumbnail(0, new CGImageThumbnailOptions())) {
#if NET
                    Assert.Null(img, "#b1");
#else
                    Assert.NotNull(img, "#b1");
                    Assert.AreEqual(IntPtr.Zero, img.Handle, "#b2");
#endif
                }
            }
        }
Example #21
0
        public Bitmap(string filename)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("Value can not be null");
            }

            try
            {
                imageSource = CGImageSource.FromUrl(NSUrl.FromFilename(filename));
                if (imageSource == null)
                {
                    throw new FileNotFoundException("File {0} not found.", filename);
                }

                InitializeImageFrame(0);
            }
            catch (Exception)
            {
                throw new FileNotFoundException("File {0} not found.", filename);
            }
        }
Example #22
0
        public IExifData GetExifData()
        {
            if (info != null)
            {
                return(new ExifData(info.ObjectForKey(UIImagePickerController.MediaMetadata) as NSDictionary));
            }

            if (filePath != null)
            {
                NSUrl url = System.IO.File.Exists(filePath) ? NSUrl.FromFilename(filePath) : NSUrl.FromString(filePath);
                if (url != null)
                {
                    CGImageSource source = CGImageSource.FromUrl(url);
                    if (source != null)
                    {
                        return(new ExifData(source.CopyProperties((NSDictionary)null, 0)));
                    }
                }
            }

            return(new ExifData());
        }
Example #23
0
        protected INativeObject GetINativeInstance(Type t)
        {
            var ctor = t.GetConstructor(Type.EmptyTypes);

            if ((ctor != null) && !ctor.IsAbstract)
            {
                return(ctor.Invoke(null) as INativeObject);
            }

            if (!NativeObjectInterfaceType.IsAssignableFrom(t))
            {
                throw new ArgumentException("t");
            }
            switch (t.Name)
            {
            case "CFAllocator":
                return(CFAllocator.SystemDefault);

            case "CFBundle":
                var bundles = CFBundle.GetAll();
                if (bundles.Length > 0)
                {
                    return(bundles [0]);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Could not create the new instance for type {0}.", t.Name));
                }

            case "CFNotificationCenter":
                return(CFNotificationCenter.Darwin);

            case "CFReadStream":
            case "CFStream":
                CFReadStream  readStream;
                CFWriteStream writeStream;
                CFStream.CreatePairWithSocketToHost("www.google.com", 80, out readStream, out writeStream);
                return(readStream);

            case "CFWriteStream":
                CFStream.CreatePairWithSocketToHost("www.google.com", 80, out readStream, out writeStream);
                return(writeStream);

            case "CFUrl":
                return(CFUrl.FromFile("/etc"));

            case "CFPropertyList":
                return(CFPropertyList.FromData(NSData.FromString("<string>data</string>")).PropertyList);

            case "DispatchData":
                return(DispatchData.FromByteBuffer(new byte [] { 1, 2, 3, 4 }));

            case "AudioFile":
                var path = Path.GetFullPath("1.caf");
                var af   = AudioFile.Open(CFUrl.FromFile(path), AudioFilePermission.Read, AudioFileType.CAF);
                return(af);

            case "CFHTTPMessage":
                return(CFHTTPMessage.CreateEmpty(false));

            case "CFMutableString":
                return(new CFMutableString("xamarin"));

            case "CGBitmapContext":
                byte[] data = new byte [400];
                using (CGColorSpace space = CGColorSpace.CreateDeviceRGB()) {
                    return(new CGBitmapContext(data, 10, 10, 8, 40, space, CGBitmapFlags.PremultipliedLast));
                }

            case "CGContextPDF":
                var filename = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments) + "/t.pdf";
                using (var url = new NSUrl(filename))
                    return(new CGContextPDF(url));

            case "CGColorConversionInfo":
                var cci = new GColorConversionInfoTriple()
                {
                    Space     = CGColorSpace.CreateGenericRgb(),
                    Intent    = CGColorRenderingIntent.Default,
                    Transform = CGColorConversionInfoTransformType.ApplySpace
                };
                return(new CGColorConversionInfo((NSDictionary)null, cci, cci, cci));

            case "CGDataConsumer":
                using (NSMutableData destData = new NSMutableData()) {
                    return(new CGDataConsumer(destData));
                }

            case "CGDataProvider":
                filename = "xamarin1.png";
                return(new CGDataProvider(filename));

            case "CGFont":
                return(CGFont.CreateWithFontName("Courier New"));

            case "CGPattern":
                return(new CGPattern(
                           new RectangleF(0, 0, 16, 16),
                           CGAffineTransform.MakeIdentity(),
                           16, 16,
                           CGPatternTiling.NoDistortion,
                           true,
                           (cgc) => {}));

            case "CMBufferQueue":
                return(CMBufferQueue.CreateUnsorted(2));

            case "CTFont":
                CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
                {
                    FamilyName = "Courier",
                    StyleName  = "Bold",
                    Size       = 16.0f
                };
                using (var fd = new CTFontDescriptor(fda))
                    return(new CTFont(fd, 10));

            case "CTFontCollection":
                return(new CTFontCollection(new CTFontCollectionOptions()));

            case "CTFontDescriptor":
                fda = new CTFontDescriptorAttributes();
                return(new CTFontDescriptor(fda));

            case "CTTextTab":
                return(new CTTextTab(CTTextAlignment.Left, 2));

            case "CTTypesetter":
                return(new CTTypesetter(new NSAttributedString("Hello, world",
                                                               new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("ArialMT", 24)
                })));

            case "CTFrame":
                var framesetter = new CTFramesetter(new NSAttributedString("Hello, world",
                                                                           new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("ArialMT", 24)
                }));
                var bPath = UIBezierPath.FromRect(new RectangleF(0, 0, 3, 3));
                return(framesetter.GetFrame(new NSRange(0, 0), bPath.CGPath, null));

            case "CTFramesetter":
                return(new CTFramesetter(new NSAttributedString("Hello, world",
                                                                new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("ArialMT", 24)
                })));

            case "CTGlyphInfo":
                return(new CTGlyphInfo("copyright", new CTFont("ArialMY", 24), "Foo"));

            case "CTLine":
                return(new CTLine(new NSAttributedString("Hello, world",
                                                         new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("ArialMT", 24)
                })));

            case "CGImageDestination":
                var storage = new NSMutableData();
                return(CGImageDestination.Create(new CGDataConsumer(storage), "public.png", 1));

            case "CGImageMetadataTag":
                using (NSString name = new NSString("tagName"))
                    using (var value = new NSString("value"))
                        return(new CGImageMetadataTag(CGImageMetadataTagNamespaces.Exif, CGImageMetadataTagPrefixes.Exif, name, CGImageMetadataType.Default, value));

            case "CGImageSource":
                filename = "xamarin1.png";
                return(CGImageSource.FromUrl(NSUrl.FromFilename(filename)));

            case "SecPolicy":
                return(SecPolicy.CreateSslPolicy(false, null));

            case "SecIdentity":
                using (var options = NSDictionary.FromObjectAndKey(new NSString("farscape"), SecImportExport.Passphrase)) {
                    NSDictionary[] array;
                    var            result = SecImportExport.ImportPkcs12(farscape_pfx, options, out array);
                    if (result != SecStatusCode.Success)
                    {
                        throw new InvalidOperationException(string.Format("Could not create the new instance for type {0} due to {1}.", t.Name, result));
                    }
                    return(new SecIdentity(array [0].LowlevelObjectForKey(SecImportExport.Identity.Handle)));
                }

            case "SecTrust":
                X509Certificate x = new X509Certificate(mail_google_com);
                using (var policy = SecPolicy.CreateSslPolicy(true, "mail.google.com"))
                    return(new SecTrust(x, policy));

            case "SslContext":
                return(new SslContext(SslProtocolSide.Client, SslConnectionType.Stream));

            case "UIFontFeature":
                return(new UIFontFeature(CTFontFeatureNumberSpacing.Selector.ProportionalNumbers));

            case "NetworkReachability":
                return(new NetworkReachability(IPAddress.Loopback, null));

            case "VTCompressionSession":
            case "VTSession":
                return(VTCompressionSession.Create(1024, 768, CMVideoCodecType.H264, (sourceFrame, status, flags, buffer) => { }, null, (CVPixelBufferAttributes)null));

            case "VTFrameSilo":
                return(VTFrameSilo.Create());

            case "VTMultiPassStorage":
                return(VTMultiPassStorage.Create());

            case "CFString":
                return(new CFString("test"));

            case "DispatchBlock":
                return(new DispatchBlock(() => { }));

            case "DispatchQueue":
                return(new DispatchQueue("com.example.subsystem.taskXYZ"));

            case "DispatchGroup":
                return(DispatchGroup.Create());

            case "CGColorSpace":
                return(CGColorSpace.CreateDeviceCmyk());

            case "CGGradient":
                CGColor[] cArray = { UIColor.Black.CGColor, UIColor.Clear.CGColor, UIColor.Blue.CGColor };
                return(new CGGradient(null, cArray));

            case "CGImage":
                filename = "xamarin1.png";
                using (var dp = new CGDataProvider(filename))
                    return(CGImage.FromPNG(dp, null, false, CGColorRenderingIntent.Default));

            case "CGColor":
                return(UIColor.Black.CGColor);

            case "CMClock":
                return(CMClock.HostTimeClock);

            case "CMTimebase":
                return(new CMTimebase(CMClock.HostTimeClock));

            case "CVPixelBufferPool":
                return(new CVPixelBufferPool(
                           new CVPixelBufferPoolSettings(),
                           new CVPixelBufferAttributes(CVPixelFormatType.CV24RGB, 100, 50)
                           ));

            case "SecCertificate":
                using (var cdata = NSData.FromArray(mail_google_com))
                    return(new SecCertificate(cdata));

            case "SecCertificate2":
                using (var cdata = NSData.FromArray(mail_google_com))
                    return(new SecCertificate2(new SecCertificate(cdata)));

            case "SecTrust2":
                X509Certificate x2 = new X509Certificate(mail_google_com);
                using (var policy = SecPolicy.CreateSslPolicy(true, "mail.google.com"))
                    return(new SecTrust2(new SecTrust(x2, policy)));

            case "SecIdentity2":
                using (var options = NSDictionary.FromObjectAndKey(new NSString("farscape"), SecImportExport.Passphrase)) {
                    NSDictionary[] array;
                    var            result = SecImportExport.ImportPkcs12(farscape_pfx, options, out array);
                    if (result != SecStatusCode.Success)
                    {
                        throw new InvalidOperationException(string.Format("Could not create the new instance for type {0} due to {1}.", t.Name, result));
                    }
                    return(new SecIdentity2(new SecIdentity(array [0].LowlevelObjectForKey(SecImportExport.Identity.Handle))));
                }

            case "SecKey":
                SecKey private_key;
                SecKey public_key;
                using (var record = new SecRecord(SecKind.Key)) {
                    record.KeyType       = SecKeyType.RSA;
                    record.KeySizeInBits = 512;                     // it's not a performance test :)
                    SecKey.GenerateKeyPair(record.ToDictionary(), out public_key, out private_key);
                    return(private_key);
                }

            case "SecAccessControl":
                return(new SecAccessControl(SecAccessible.WhenPasscodeSetThisDeviceOnly));

            default:
                throw new InvalidOperationException(string.Format("Could not create the new instance for type {0}.", t.Name));
            }
        }
Example #24
0
 public AnimatedImage(NSUrl url)
     : this(CGImageSource.FromUrl(url, null))
 {
 }
        public static UIImageView GetAnimatedImageView(string url, UIImageView imageView = null)
        {
            var sourceRef = CGImageSource.FromUrl(NSUrl.FromString(url));

            return(CreateAnimatedImageView(sourceRef, imageView));
        }
Example #26
0
        private static List <PhotoModel> extractMetadata(string path)
        {
            List <PhotoModel> photoLocations = new List <PhotoModel>();

            // reading from directory
            string[] files = System.IO.Directory.GetFiles(path, "*.jp*g");
            foreach (var item in files)
            {
                Console.WriteLine(item.ToString());
            }
            if (files.Length == 0)
            {
                Console.Error.WriteLine("No matching files found.");
                Environment.Exit(1);
            }


            PhotoModel ds = new PhotoModel();


            // extracting metadata for each file
            foreach (string file in files)
            {
                Console.WriteLine("_________________________ NEW PHOTO _________________________");
#if __IOS__
                var           url = new NSUrl(file, false); // could be an NSUrl to asset lib...
                CGImageSource myImageSource;
                myImageSource = CGImageSource.FromUrl(url, null);
                var ns = new NSDictionary();
                var imageProperties = myImageSource.CopyProperties(ns, 0);
                var width           = imageProperties[CGImageProperties.PixelWidth];
                var height          = imageProperties[CGImageProperties.PixelHeight];
                Console.WriteLine("Dimensions: {0}x{1}", width, height);

                // for debugging output all the image metadata
                Console.WriteLine(imageProperties.DescriptionInStringsFileFormat);
                hm.Clear();

                // tiff
                var tiff   = imageProperties.ObjectForKey(CGImageProperties.TIFFDictionary) as NSDictionary;
                var artist = tiff[CGImageProperties.TIFFArtist];
                var make   = tiff[CGImageProperties.TIFFMake];
                var model  = tiff[CGImageProperties.TIFFModel];
                if (artist != null)
                {
                    hm.Add("owner", artist.ToString());
                }
                else
                {
                    hm.Add("owner", make + " " + model);
                }

                // exif
                var exif             = imageProperties.ObjectForKey(CGImageProperties.ExifAuxDictionary) as NSDictionary;
                var dateTimeOriginal = tiff[CGImageProperties.ExifDateTimeOriginal];
                if (dateTimeOriginal != null)
                {
                    hm.Add("date", dateTimeOriginal.ToString());
                }
                else
                {
                    hm.Add("date", "");
                }

                // gps
                var gps    = imageProperties.ObjectForKey(CGImageProperties.GPSDictionary) as NSDictionary;
                var lat    = gps[CGImageProperties.GPSLatitude];
                var latref = gps[CGImageProperties.GPSLatitudeRef];
                var lon    = gps[CGImageProperties.GPSLongitude];
                var lonref = gps[CGImageProperties.GPSLongitudeRef];
                var loc    = String.Format("GPS: {0} {1}, {2} {3}", lat, latref, lon, lonref);
                hm.Add("lat", lat.ToString());
                hm.Add("lng", lon.ToString());
                Console.WriteLine(loc);
                string coordinate = lat + "," + lon;
                ReverseGeocode(hm, coordinate);

                photoLocations.Add(new PhotoModel(Double.Parse(lat.ToString()), Double.Parse(lon.ToString()), file, hm));
#endif

#if Android
                photoLocations.AddRange(ExtractMetadataPerPhoto(file, out string fullAdress));
#endif
            }
            return(photoLocations);
        }