Exemplo n.º 1
0
        public static IImageSourceHandler?GetHandler(this ImageSource?imageSource)
        {
            if (imageSource == null || imageSource.IsEmpty)
            {
                return(null);
            }

            return(Registrar.Registered.GetHandlerForObject <IImageSourceHandler>(imageSource));

            //if (imageSource is UriImageSource)
            //{
            //    return new ImageLoaderSourceHandler();
            //}
            //else if (imageSource is FileImageSource)
            //{
            //    return new FileImageSourceHandler();
            //}
            //else if (imageSource is StreamImageSource)
            //{
            //    return new StreamImagesourceHandler();
            //}
            //else
            //{

            //}
        }
 /// <inheritdoc />
 public override ImageSource ReadJson(JsonReader reader, Type objectType, ImageSource?existingValue, bool hasExistingValue,
                                      JsonSerializer serializer)
 {
     if (reader.Value is string value && !string.IsNullOrWhiteSpace(value))
     {
         return(ImageSource.FromUri(new Uri(value)));
     }
 private void AttachDesignSource(ImageSource?source)
 {
     if (_image != null)
     {
         _image.Source = source;
     }
 }
Exemplo n.º 4
0
            private static bool ImageEquals(ImageSource?x, ImageSource?y)
            {
                if (Equals(x, y))
                {
                    return(true);
                }
                if ((x == null) != (y == null))
                {
                    return(false);
                }

                // They can't both be null or Equals would have returned true
                // and if any is null, the previous would have detected it
                // ReSharper disable PossibleNullReferenceException
                if (x !.GetType() != y !.GetType())
                {
                    return(false);
                }
                // ReSharper restore PossibleNullReferenceException

                Uri?xUri = GetUri(x);
                Uri?yUri = GetUri(y);

                return(xUri != null && xUri == yUri);
            }
Exemplo n.º 5
0
 private static void FreezeImage(ImageSource?image)
 {
     if (image == null || image.IsFrozen || !image.CanFreeze)
     {
         return;
     }
     image.Freeze();
 }
Exemplo n.º 6
0
 private void tryLoadAndSetImage(Button button, ImageSource?imageSource)
 {
     if (imageSource != null)
     {
         var image = new Image();
         image.Source   = imageSource;
         button.Content = image;
     }
 }
Exemplo n.º 7
0
    /// <summary>
    /// Default constructor for an action
    /// </summary>
    /// <param name="header">The item header</param>
    /// <param name="iconSource">The icon source</param>
    /// <param name="command">The item command</param>
    /// <param name="minUserLevel">The minimum user level for the action</param>
    public ActionItemViewModel(string?header, ImageSource?iconSource, ICommand?command, UserLevel minUserLevel = UserLevel.Normal)
    {
        iconSource?.Freeze();

        Header       = header;
        IconSource   = iconSource;
        Command      = command;
        MinUserLevel = minUserLevel;
    }
Exemplo n.º 8
0
        Stream?GetStreamFromImageSource(ImageSource?imageSource)
        {
            var streamImageSource = (StreamImageSource?)imageSource;

            var cancellationToken = System.Threading.CancellationToken.None;
            var task = streamImageSource?.Stream(cancellationToken);

            return(task?.Result);
        }
 /// <inheritdoc />
 public override void WriteJson(JsonWriter writer, ImageSource?value, JsonSerializer serializer)
 {
     if (value != null && value is UriImageSource uriValue)
     {
         writer.WriteValue(uriValue.Uri.ToString());
     }
     else
     {
         writer.WriteUndefined();
     }
 }
Exemplo n.º 10
0
        public List <ImageMetaData> Get(ImageSource?source, ImageGenre?genre)
        {
            var sqliteConnection = new SQLiteConnection(_configurationAccessor.GetDatabaseConnectionString());

            using (var model = new EntityFramework.Model(sqliteConnection))
            {
                var allImages = model.ImageMetaDatas.ToList();
                return(model.ImageMetaDatas
                       .Where(imd => (!source.HasValue || imd.SourceId == source.Value) && (!genre.HasValue || imd.GenreId == genre.Value))
                       .ToList());
            }
        }
Exemplo n.º 11
0
        public static async Task SetPhoto()
        {
            if (token == null || userId == 0)
            {
                return;
            }

            var url = await AuthorizationClient.GetPhoto(token, userId);

            Preference.Set(PhotoKey, url.ToString());
            photoSource = ImageSource.FromUri(url);
        }
        private void AddInstallationPath(InstallationPaths paths)
        {
            Icon?       icon   = System.Drawing.Icon.ExtractAssociatedIcon(paths.ChromeExePath !);
            ImageSource?source = icon != null?Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()) : null;                // Turn the icon into an ImageSource for the WPF gui

            this.mainModel.BrowserListModel.ElementList.Add(new InstallationElement(paths.Name, paths)
            {
                Description = paths.ChromeDllPath,
                IconImage   = source,
                Tooltip     = paths.ChromeExePath + " & " + paths.ChromeDllPath,
                IsSelected  = true
            });
        }
Exemplo n.º 13
0
 public ButtonViewModel(
     Action action,
     Func <bool>?canExecute  = null,
     string?title            = null,
     ImageSource?imageSource = null,
     bool isEnabled          = true)
 {
     _command = new Command(
         action,
         () => IsEnabled && (canExecute?.Invoke() ?? true));
     _title       = title;
     _imageSource = imageSource;
     _isEnabled   = isEnabled;
 }
Exemplo n.º 14
0
        public NavigationInfo(Page content, byte[]?icon = default, NavigationOrder desired = NavigationOrder.AbsoluteStart)
        {
            if (desired == NavigationOrder.Null)
            {
                throw new NullReferenceException($"{nameof(desired)} was set to null location which is invalid.");
            }
            this.content = content;
            this.desired = desired;

            if (icon != null)
            {
                this.icon = ImageConverter.ByteToImageSource(icon);
                hasIcon   = true;
            }
        }
Exemplo n.º 15
0
 public ProgressUI(Window?owner, string title, string desc, ImageSource?image, CancellationToken cancel)
 {
     InitializeComponent();
     Owner              = owner;
     Icon               = owner?.Icon;
     Title              = title;
     Image              = image;
     Description        = desc;
     Done               = new ManualResetEvent(false);
     m_cancel           = CancellationTokenSource.CreateLinkedTokenSource(cancel);
     ProgressBarVisible = true;
     AllowCancel        = true;
     CancelEnabled      = true;
     SignalCancel       = Command.Create(this, () => CancelPending = true);
     DataContext        = this;
 }
Exemplo n.º 16
0
 public ButtonViewModel(
     Func <Task> asyncAction,
     Func <bool>?canExecute  = null,
     string?title            = null,
     ImageSource?imageSource = null,
     bool isEnabled          = true)
 {
     _command = new Command(
         async() =>
     {
         IsEnabled = false;
         await asyncAction();
         IsEnabled = true;
     },
         () => IsEnabled && (canExecute?.Invoke() ?? true));
     _title       = title;
     _imageSource = imageSource;
     _isEnabled   = isEnabled;
 }
Exemplo n.º 17
0
        private async Task Reload(bool removeCache)
        {
            if (IsLoading)
            {
                return;
            }

            IsLoading = true;
            _source   = await LoadImage(removeCache, _cancellationTokenSource.Token);

            IsLoading = false;
            if (_source != null)
            {
                OnPropertyChanged(nameof(Source));
            }
            else
            {
                Reload(true);
            }
        }
Exemplo n.º 18
0
        public async Task <bool> IsImageSourceValidAsync(ImageSource?source)
        {
            var handler = GetHandler(source);

            if (handler == null)
            {
                return(false);
            }

#if TIZEN
            return(await handler.LoadImageAsync(new NImage(XForms.NativeParent), source).ConfigureAwait(false));
#elif MONOANDROID
            var imageSource = await handler.LoadImageAsync(source, ToolkitPlatform.Context).ConfigureAwait(false);

            return(imageSource != null);
#else
            var imageSource = await handler.LoadImageAsync(source).ConfigureAwait(false);

            return(imageSource != null);
#endif
        }
Exemplo n.º 19
0
        private static bool TryGetFileIcon(string path, [NotNullWhen(true)] out ImageSource?icon)
        {
            icon = null;
            try
            {
                var ic = Icon.ExtractAssociatedIcon(path);

                if (ic is null)
                {
                    return(false);
                }

                icon = ToImageSource(ic);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 20
0
        IImageSourceHandler?GetHandler(ImageSource?source)
        {
            if (source is UriImageSource)
            {
                return(new UriImageSourceHandler());
            }

            if (source is StreamImageSource)
            {
                return(new StreamImageSourceHandler());
            }

#if !NET471
            if (source is GravatarImageSource)
            {
                return(new GravatarImageSourceHandler());
            }
#endif

#if !TIZEN
            if (source is FontImageSource)
            {
                return(new FontImageSourceHandler());
            }
#endif

            if (source is FileImageSource fileSource)
            {
#if !MONOANDROID
                if (!File.Exists(fileSource.File))
                {
                    return(null);
                }
#endif
                return(new FileImageSourceHandler());
            }

            return(null);
        }
        public object?Convert(object?value, Type targetType, object?parameter, CultureInfo culture)
        {
            var file = value?.ToString();

            if (icon == null && file != null && File.Exists(file))
            {
                using var nativeIcon = Icon.ExtractAssociatedIcon(file);

                if (nativeIcon == null)
                {
                    return(Application.Current.Resources.FindName("IconDocument") as BitmapSource);
                }

                icon = Imaging.CreateBitmapSourceFromHIcon(
                    nativeIcon.Handle,
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromEmptyOptions()
                    );
            }

            return(icon);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Gets an image from storage.
        /// If image is not foud returns default image.
        /// </summary>
        /// <param name="name">Relative image path</param>
        /// <returns>Loaded image</returns>
        public static ImageSource GetImage(string?name)
        {
            ImageSource?source = null;

            try
            {
                if (!String.IsNullOrWhiteSpace(name))
                {
                    string filename = GetImagePath(name);
                    if (File.Exists(filename))
                    {
                        source = ImageSource.FromFile(filename);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error getting image filename: {e.Message}");
            }

            return(source ?? ImageSource.FromFile(DEFAULT_IMAGE_NAME));
        }
Exemplo n.º 23
0
        private static GifBitmapDecoder?GetGifBitmapDecoder(ImageSource?source)
        {
            GifBitmapDecoder?decoder = null;

            if (source is BitmapFrame bitmapFrame)
            {
                decoder = bitmapFrame.Decoder as GifBitmapDecoder;
            }
            else if (source is BitmapImage bitmap)
            {
                if (bitmap.UriSource != null)
                {
                    decoder = BitmapDecoder.Create(bitmap.UriSource, BitmapCreateOptions.None, BitmapCacheOption.OnLoad) as GifBitmapDecoder;
                }
                else if (bitmap.StreamSource != null)
                {
                    bitmap.StreamSource.Seek(0, SeekOrigin.Begin);
                    decoder = BitmapDecoder.Create(bitmap.StreamSource, BitmapCreateOptions.None, BitmapCacheOption.OnLoad) as GifBitmapDecoder;
                }
            }

            return(decoder);
        }
Exemplo n.º 24
0
 public static void PlaceholderFromFontImageSource(FontImageSource fontImageSource) =>
 PlaceholderImageSource = fontImageSource;
Exemplo n.º 25
0
 public static void PlaceholderFromResource(string resourceName, Assembly assembly) =>
 PlaceholderImageSource = ImageSource.FromResource(resourceName, assembly);
Exemplo n.º 26
0
 void InitializeImageData()
 {
     imageData   = (byte[])((BuiltInResourceData)ResourceElement.ResourceData).Data;
     imageSource = ImageResourceUtilities.CreateImageSource(imageData);
 }
Exemplo n.º 27
0
 private async void UpdateIcon()
 {
     Icon = await IconHelper.GetIconAsync(ApplicationName).ConfigureAwait(false); //FIXME: This is now expanded... Is that a problem?!?
 }
Exemplo n.º 28
0
 public MobileReferringSiteModel(ReferringSiteModel referringSiteModel, ImageSource?favIcon) : base(referringSiteModel.TotalCount, referringSiteModel.TotalUniqueCount, referringSiteModel.Referrer)
 {
     FavIcon = favIcon;
 }
Exemplo n.º 29
0
 public TabButton(string?text, ImageSource?icon)
     : this()
 {
     m_def_tab_text = text ?? string.Empty;
     m_def_tab_icon = icon;
 }
Exemplo n.º 30
0
        private string GetImageCount(Session session, string line, ImageSource?imageSource, ImageGenre?imageGenre)
        {
            var imageCount = _imageAccessor.Get(imageSource, imageGenre).Count;

            return(imageCount.ToString());
        }