Exemple #1
0
        private static void IconPropertyChanged(BindableObject bindable, object oldValue, object newValue)
        {
            var control = (CustomEntry)bindable;

            iconPath            = newValue.ToString();
            control.Icon.Source = SvgImageSource.FromResource(newValue.ToString());
        }
Exemple #2
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var svg = new SvgImageSource();

            using (HttpClient client = new HttpClient())
            {
                try
                {
                    var response = client.GetAsync(new Uri(value as string)).Result;
                    if (response != null && response.StatusCode == HttpStatusCode.OK)
                    {
                        using (var stream = response.Content.ReadAsStreamAsync().Result)
                        {
                            using (var memStream = new MemoryStream())
                            {
                                stream.CopyToAsync(memStream);
                                memStream.Position = 0;
                                svg.SetSourceAsync(memStream.AsRandomAccessStream());
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            return(svg);
        }
Exemple #3
0
        private async void MyBtn_Click(object sender, RoutedEventArgs e)
        {
            using (HttpClient client = new HttpClient())
            {
                var svg = new SvgImageSource();
                try
                {
                    var response = await client.GetAsync(new Uri("http://www.iconsvg.com/Home/downloadPicture?route=1333158662629220352&name=%E5%9C%86%E5%BD%A2%E7%9A%84_circular164"));

                    if (response != null && response.StatusCode == HttpStatusCode.OK)
                    {
                        using (var stream = await response.Content.ReadAsStreamAsync())
                        {
                            using (var memStream = new MemoryStream())
                            {
                                await stream.CopyToAsync(memStream);

                                memStream.Position = 0;
                                await svg.SetSourceAsync(memStream.AsRandomAccessStream());

                                MyImageView.Source = svg;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
    public async void Open(Image display)
    {
        try
        {
            FileOpenPicker picker = new FileOpenPicker()
            {
                SuggestedStartLocation = PickerLocationId.PicturesLibrary
            };
            picker.FileTypeFilter.Add(".svg");
            StorageFile open = await picker.PickSingleFileAsync();

            if (open != null)
            {
                SvgImageSource source = new SvgImageSource()
                {
                    RasterizePixelHeight = display.ActualHeight,
                    RasterizePixelWidth  = display.ActualWidth
                };
                if (await source.SetSourceAsync(await open.OpenReadAsync())
                    == SvgImageSourceLoadStatus.Success)
                {
                    display.Source = source;
                }
            }
        }
        finally
        {
            // Ignore Exceptions
        }
    }
Exemple #5
0
        private async void item_source_Tapped(object sender, TappedRoutedEventArgs e)
        {
            try
            {
                string ImageLink = string.Empty;
                if (item_source.Source.GetType() == typeof(BitmapImage))
                {
                    BitmapImage bitmapSource = item_source.Source as BitmapImage;
                    ImageLink = bitmapSource.UriSource.ToString();

                    //Check if media is a gif(v) file
                    if (ImageLink.ToLower().Contains(".gif"))
                    {
                        ToolTipService.SetToolTip(item_video, "Play the video");
                        item_video_status.Source = await AVImage.LoadBitmapImage("ms-appx:///Assets/iconVideoPlay.png", false);

                        bitmapSource.Stop();
                    }
                }
                else if (item_source.Source.GetType() == typeof(SvgImageSource))
                {
                    SvgImageSource SvgSource = item_source.Source as SvgImageSource;
                    ImageLink = SvgSource.UriSource.ToString();
                }

                System.Diagnostics.Debug.WriteLine("Itemviewer image tapped: " + ImageLink);
                ImagePopup imageViewer = new ImagePopup();
                await imageViewer.OpenPopup(ImageLink);
            }
            catch { }
        }
Exemple #6
0
        private void SetWeatherItem(WeatherItem item)
        {
            _weather = item;

            var path = "";

            if (ThemeSelectorService.Theme == ElementTheme.Light)
            {
                path = "ms-appx:///Assets/WeatherIconsBlack/";
            }
            else
            {
                path = "ms-appx:///Assets/WeatherIconsWhite/";
            }
            var            iconFilename = _weather.Icon + ".svg";
            var            iconFilePath = Path.Combine(path, iconFilename);
            SvgImageSource source       = new SvgImageSource(new Uri(iconFilePath));

            weatherIconImage.Source = source;
            var tempList = _weather.Temp.Split('.');

            tempTextBlock.Text      = tempList[0] + " \u00B0C";
            pressureTextBlock.Text  = _weather.Pressure + " hPa";
            windSpeedTextBlock.Text = "Wind speed: " + _weather.Wind_speed + " m/s";
        }
Exemple #7
0
        private void TypePlaySongImage_Tapped(object sender, EventArgs e)
        {
            var viewModel = DataSource;

            switch (viewModel.TypePlayMusic)
            {
            case TYPE_PLAY_MUSIC.PLAY_REPEAT_ALL:
            {
                viewModel.TypePlayMusic  = TYPE_PLAY_MUSIC.PLAY_REPEAT_ONE;
                TypePlaySongImage.Source = SvgImageSource.FromResource("NuMusic.Resources.Svg.icon_play_repeat1.svg");
                break;
            }

            case TYPE_PLAY_MUSIC.PLAY_REPEAT_ONE:
            {
                viewModel.TypePlayMusic  = TYPE_PLAY_MUSIC.PLAY_RANDOM;
                TypePlaySongImage.Source = SvgImageSource.FromResource("NuMusic.Resources.Svg.icon_play_random.svg");
                break;
            }

            case TYPE_PLAY_MUSIC.PLAY_RANDOM:
            {
                viewModel.TypePlayMusic  = TYPE_PLAY_MUSIC.PLAY_REPEAT_ALL;
                TypePlaySongImage.Source = SvgImageSource.FromResource("NuMusic.Resources.Svg.icon_play_repeat.svg");
                break;
            }
            }
        }
        /// <inheritdoc />
        public override async Task InvokeAsync(ILoadingContext <ImageSource> context, LoadingPipeDelegate <ImageSource> next, CancellationToken cancellationToken = default)
        {
            if (context.Current is Stream stream)
            {
                if (!stream.CanSeek)
                {
                    var memoryStream = new MemoryStream();
                    await stream.CopyToAsync(memoryStream);

                    if (!ReferenceEquals(stream, context.OriginSource))
                    {
                        // if the stream generated by the pipe then dispose it.
                        stream.Dispose();
                    }
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    stream = memoryStream;
                }

                var isSvg = IsSvg(stream);

                var tcs = new TaskCompletionSource <object?>();
                context.InvokeOnUIThread(async() =>
                {
                    try
                    {
                        if (isSvg)
                        {
                            var bitmap = new SvgImageSource();
                            context.AttachSource(bitmap);
                            var svgImageLoadStatus = await bitmap.SetSourceAsync(stream.AsRandomAccessStream());
                            if (svgImageLoadStatus != SvgImageSourceLoadStatus.Success)
                            {
                                throw new SvgImageFailedStatusException(svgImageLoadStatus);
                            }
                            cancellationToken.ThrowIfCancellationRequested();
                            context.Current = bitmap;
                        }
                        else
                        {
                            // https://docs.microsoft.com/en-us/windows/uwp/debug-test-perf/optimize-animations-and-media?redirectedfrom=MSDN#right-sized-decoding
                            // Set source after attached to the XAML tree

                            var bitmap = new BitmapImage();
                            context.AttachSource(bitmap);
                            await bitmap.SetSourceAsync(stream.AsRandomAccessStream());
                            cancellationToken.ThrowIfCancellationRequested();
                            context.Current = bitmap;
                        }
                        tcs.SetResult(null);
                    }
                    catch (Exception ex)
                    {
                        tcs.SetException(ex);
                    }
                });
                await tcs.Task;
            }

            await next(context, cancellationToken);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string source)
            {
                sourceString = source;

                var sourceUri = new Uri(sourceString);

                if (!sourceString.ToString().StartsWith("resource://", StringComparison.OrdinalIgnoreCase))
                {
                    throw new Exception("Only resource:// scheme is supported");
                }

                var parts = sourceUri.OriginalString.Substring(11).Split('?');
                resourceName = parts.First();

                if (parts.Count() > 1)
                {
                    var name         = Uri.UnescapeDataString(sourceUri.Query.Substring(10));
                    var assemblyName = new AssemblyName(name);
                    assembly = Assembly.Load(assemblyName);
                }

                var svgImageSource = new SvgImageSource(Xamarin.Forms.ImageSource.FromStream(LoadFile), 100, 100, true, null);

                return(svgImageSource);
            }

            return(null);
        }
Exemple #10
0
        //Load SvgImage
        internal static async Task <SvgImageSource> LoadSvgImage(string Path)
        {
            if (!string.IsNullOrWhiteSpace(Path) && Path.ToLower().Contains(".svg"))
            {
                TaskCompletionSource <SvgImageSource> TaskResult = new TaskCompletionSource <SvgImageSource>();
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    try
                    {
                        SvgImageSource SvgToBitmapImage = new SvgImageSource();
                        SvgToBitmapImage.UriSource      = new Uri(Path, UriKind.RelativeOrAbsolute);
                        TaskResult.SetResult(SvgToBitmapImage);
                    }
                    catch
                    {
                        TaskResult.SetResult(null);
                    }
                });

                return(await TaskResult.Task);
            }
            else
            {
                return(null);
            }
        }
        private void CreateInterfaceSquare(string text, string imagePath)
        {
            Uri            uri         = new Uri(imagePath, UriKind.RelativeOrAbsolute);
            SvgImageSource imageSource = new SvgImageSource(uri);

            Grid grid = new Grid();

            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(iconSizeMultiplier, GridUnitType.Star)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });

            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(4, GridUnitType.Star)
            });
            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Star)
            });


            var image = new Image()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch,
                Source  = imageSource,
                Stretch = Stretch.Uniform,
            };

            var textBlock = new TextBlock()
            {
                Text                = text,
                Foreground          = new SolidColorBrush(Colors.Black),
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Center,
                FontSize            = 20,
                TextAlignment       = TextAlignment.Center
            };

            grid.Children.Add(image);
            grid.Children.Add(textBlock);

            Grid.SetRow(textBlock, 2);
            Grid.SetColumnSpan(textBlock, 3);
            Grid.SetColumn(image, 1);

            grid.Background = new SolidColorBrush(Colors.White);

            AddSquare(grid);
        }
        public App()
        {
            InitializeComponent();

            SvgImageSource.RegisterAssembly();

            MainPage = new MainPage();
        }
Exemple #13
0
        protected override void OnInitialized()
        {
            InitializeComponent();

            SvgImageSource.RegisterAssembly();

            NavigationService.NavigateAsync("/NavigationPage/MainPage");
        }
Exemple #14
0
        private async void RenderFourierTransform()
        {
            var            stream = await ImageListClass.FileSourceList[myID].OpenAsync(FileAccessMode.Read);
            SvgImageSource image  = new SvgImageSource();
            await image.SetSourceAsync(stream);

            NormalImageControl.Source = image;
        }
Exemple #15
0
        public App()
        {
            InitializeComponent();
            // CrossMediaManager.Current.Init();
            SvgImageSource.RegisterAssembly();

            MainPage = new MainPage();
        }
        public App()
        {
            InitializeComponent();

            SvgImageSource.RegisterAssembly();

            MainPage = new NavigationPage(new Sensor());
        }
Exemple #17
0
 public virtual SvgCachedImage Svg(string ressourceId)
 {
     return new SvgCachedImage {
         Source = SvgImageSource.FromResource(ressourceId, FindCallingAssembly())
         //WidthRequest = 100,
         //HeightRequest = 100,
     };
 }
 public InputPrompt()
 {
     _image         = new Image();
     _source        = new SvgImageSource();
     _image.Source  = _source;
     _assembly      = this.GetType().GetTypeInfo().Assembly;
     this.Loaded   += InputPrompt_Loaded;
     this.Unloaded += InputPrompt_Unloaded;
 }
Exemple #19
0
        // Token: 0x060004B4 RID: 1204 RVA: 0x0002050C File Offset: 0x0001E70C
        private static void OnIconChanged(BindableObject bindable, object oldValue, object newValue)
        {
            FuncView funcView = bindable as FuncView;

            if (!oldValue.Equals(newValue))
            {
                funcView.image.Source = SvgImageSource.FromFile(newValue.ToString(), 0, 0, true, null);
            }
        }
Exemple #20
0
 private static void Floorplan_update(App.TrackItem item)
 {
     foreach (App.TrackItem floormap in App.Config.Items.Where(n => n.Type == Itemtypes.Floormap))
     {
         floormap.State           = UpdateOnOff(item, floormap.State);
         floormap.SvgImage.Source = SvgImageSource.FromSvgString(floormap.State);
         floormap.SvgImage.ReloadImage();
     }
 }
Exemple #21
0
        // Token: 0x060004C1 RID: 1217 RVA: 0x00020B64 File Offset: 0x0001ED64
        private static void OnIconChanged(BindableObject bindable, object oldValue, object newValue)
        {
            MineCell mineCell = bindable as MineCell;

            if (!oldValue.Equals(newValue))
            {
                mineCell.icon.Source = SvgImageSource.FromFile(newValue.ToString(), 0, 0, true, null);
            }
        }
 public SizeViewModel(Size size, Unit unit, SvgImageSource unitImage)
 {
     _size            = size;
     SizeText         = size.UnitsCount + unit.ToAbbrevation();
     Price            = size.TotalPrice;
     PricePerUnit     = size.TotalPrice / size.UnitsCount;
     PricePerUnitText = PricePerUnit.GetPriceString() + "/" + unit.ToAbbrevation();
     Image            = unitImage;
 }
Exemple #23
0
        public static async Task <SvgImageSource> StorageFileToSvgImage(StorageFile savedStorageFile)
        {
            using (var fileStream = await savedStorageFile.OpenAsync(FileAccessMode.Read))
            {
                var svgImage = new SvgImageSource();
                await svgImage.SetSourceAsync(fileStream);

                return(svgImage);
            }
        }
        /// <summary>
        /// Returns an image source for SvgImage that loads an image from given SVG image path and
        /// name.
        /// </summary>
        /// <param name="svgImageName">relative path to the SVG image file</param>
        /// <param name="fill">when not null, an alternative fill color for SVG path elements</param>
        /// <returns>image source</returns>
        public static ImageSource GetImageSource(string svgImageName, string fill = null)
        {
            var cache = DependencyService.Get <SvgImageCache>();

            Debug.Assert(cache != null, "cache object must exist");

            string svgText = cache.GetSvgImage(svgImageName, fill);

            return(SvgImageSource.FromSvgString(svgText));
        }
Exemple #25
0
        public App()
        {
            InitializeComponent();

            SvgImageSource.RegisterAssembly();

            // Instantiate objects.
            HttpWebRequest = new HttpWebRequest();

            MainPage = new MainPage();
        }
        private SvgIconTarget(string iconName, string iconFile)
        {
            IconName = iconName;
            IconFile = iconFile;


            ResourceFile = (string)ImageEnumEmbeddedResourceConverter.Convert(iconFile, null, null, null);

            ImageSource  = new EmbeddedResourceImageSource(new Uri(ResourceFile));
            ImageSource2 = SvgImageSource.FromSvgResource(ResourceFile);
        }
Exemple #27
0
        private async void LoadSvg()
        {
            generator = new SVGGenerator();
            await generator.LoadSvg();

            var generationCancellationTokenSource = new CancellationTokenSource();
            var souce = await generator.GetSourceAsync(generationCancellationTokenSource.Token);

            SvgSource = new SvgImageSource();
            await SvgSource.SetSourceAsync(souce);
        }
Exemple #28
0
        private async Task RenderSvg()
        {
            using (var stream = new InMemoryRandomAccessStream())
            {
                await RenderSvg(stream);

                var image = new SvgImageSource();
                await image.SetSourceAsync(stream);

                ResultSvgImage.Source = image;
            }
        }
Exemple #29
0
        private void OnSvgPathChanged()
        {
            if (SvgPath == null)
            {
                return;
            }

            var assemblyName      = GetType().Assembly.GetName().Name;
            var svgPathNormalized = SvgPath.Replace("/", ".");
            var svgFullPath       = $"{assemblyName}.{svgPathNormalized}";

            Source = SvgImageSource.FromResource(svgFullPath);
        }
 void tap(object sender, object e)
 {
     if (State)
     {
         SetValue(StateProperty, false);
         Image.Source = !string.IsNullOrEmpty(IconOff) ? SvgImageSource.FromFile(IconOff) : SvgImageSource.FromFile("more.svg");
     }
     else
     {
         SetValue(StateProperty, true);
         Image.Source = !string.IsNullOrEmpty(IconOn) ? SvgImageSource.FromFile(IconOn) : SvgImageSource.FromFile("more.svg");
     }
 }
        public MainPage(string[] names)
        {
            this.names = names;
            InitializeComponent();

            //FileImageSource is sealed. We can currently not derive SvgImageSource from FileImageSource.
            //FileImageSource only references a local file path. It does not contains the methods to access it.
            //var svg = new SvgImageSource { Svg = "res:images.hand", HeightRequest = 20,  ColorMapping = "ffffff=00ff00" };
            //var image = svg.Image;

            //var toolbarImage = SvgImageSource.CreateFile("res:images.hand", height: 20);

            //ToolbarItems.Add(new ToolbarItem
            //{
            //    Icon = toolbarImage,
            //    Order = ToolbarItemOrder.Primary, Command = new Command(() =>
            //    {
            //        Navigation.PushAsync(new Page2());
            //    })
            //});

            //try
            //{
            //    var image = SvgImageSource.Create("res:images.refresh");
            //    var t = 0;
            //}
            //catch (Exception e)
            //{
            //    Debug.WriteLine(e);
            //}

            var svgRefresh = new SvgImageSource
            {
                Svg = "res:images.refresh",
                HeightRequest = 15
            };
            TestButton.Image = svgRefresh.Image;
        }