Example #1
0
        public void LoadImage(MediaResult result, Action <string, Texture2D> callback, int maxSize = -1)
        {
            Util.NullArgumentTest(result);
            Util.NullArgumentTest(callback);

            callback = RuntimeHelper.ToMainThread(callback);

            if (string.IsNullOrEmpty(result.Uri))
            {
                callback("Invalid image URL.", null);
                return;
            }

            var uiImage = LoadImageAtPath(result.Uri, maxSize);

            if (uiImage == null)
            {
                callback("The image couldn't be loaded.", null);
                return;
            }

            Texture2D image = TextureUtilities.Decode(UIFunctions.UIImagePNGRepresentation(uiImage.NormalizedImage).ToBytes());

            image = Resize(image, maxSize);
            callback(null, image);
        }
Example #2
0
        public void OnNativeCallback(string error, byte[] data)
        {
            if (callback == null)
            {
                return;
            }

            RuntimeHelper.RunOnMainThread(() =>
            {
                if (error != null)
                {
                    callback(error, null);
                    return;
                }

                try
                {
                    var image = TextureUtilities.Decode(data);
                    callback(null, image);
                }
                catch (Exception e)
                {
                    callback(e.Message, null);
                }
            });
        }
Example #3
0
        public static Contact ToContact(this CNContact cnContact)
        {
            if (cnContact == null)
            {
                return(null);
            }

            return(new Contact
            {
                Id = cnContact.Identifier != null ? cnContact.Identifier.UTF8String : string.Empty,
                FirstName = cnContact.GivenName != null ? cnContact.GivenName.UTF8String : string.Empty,
                MiddleName = cnContact.MiddleName != null ? cnContact.MiddleName.UTF8String : string.Empty,
                LastName = cnContact.FamilyName != null ? cnContact.FamilyName.UTF8String : string.Empty,
                Company = cnContact.OrganizationName != null ? cnContact.OrganizationName.UTF8String : string.Empty,
                Birthday = cnContact.Birthday != null ? new DateTime?(cnContact.Birthday.ToDateTime()) : null,
                Emails = ToContactEmails(cnContact.EmailAddresses),
                PhoneNumbers = ToContactPhoneNumbers(cnContact.PhoneNumbers),
                loadPhotoFunc = () =>
                {
                    if (cnContact.ImageData == null)
                    {
                        return null;
                    }

                    UIImage image = UIImage.ImageWithData(cnContact.ImageData);
                    return TextureUtilities.Decode(UIImage.UIImagePNGRepresentation(image.NormalizedImage));
                }
            });
        }