Exemplo n.º 1
0
        async void LoadImage(View parent, int delay = 2000)
        {
            var img = new Image
            {
                SizeHeight         = 300,
                WidthSpecification = LayoutParamPolicies.MatchParent,
                Aspect             = Tizen.UIExtensions.Common.Aspect.AspectFill
            };

            img.ResourceReady += (s, e) =>
            {
                Console.WriteLine($"[{img.GetHashCode()}] Image Loaded - {img.LoadingStatus}");
            };
            parent.Add(img);
            bool run = true;

            img.RemovedFromWindow += (s, e) =>
            {
                run = false;
                (s as View).Dispose();
            };

            int count = 0;

            while (run)
            {
                var assembly     = typeof(ImageFromStream).GetTypeInfo().Assembly;
                var assemblyName = assembly.GetName().Name;
                var resourcePath = assemblyName + ".Resource." + ((count++ % 2 == 0) ? "animated.gif" : "image2.jpg");
                var stream       = assembly.GetManifestResourceStream(resourcePath);
                var result       = await img.LoadAsync(stream);

                Console.WriteLine($"[{img.GetHashCode()}] Load result : {result}");
                await Task.Delay(delay);
            }
        }
Exemplo n.º 2
0
        public override View Run()
        {
            var view = new View
            {
                Layout = new LinearLayout
                {
                    LinearAlignment   = LinearLayout.Alignment.Center,
                    LinearOrientation = LinearLayout.Orientation.Vertical,
                }
            };

            var scrollView = new ScrollView()
            {
                WidthSpecification  = LayoutParamPolicies.MatchParent,
                HeightSpecification = LayoutParamPolicies.MatchParent,
            };

            view.Add(scrollView);

            scrollView.ContentContainer.Layout = new LinearLayout
            {
                LinearOrientation = LinearLayout.Orientation.Vertical,
            };

            {
                var img = new Image
                {
                    WidthResizePolicy = ResizePolicyType.FillToParent,
                    SizeHeight        = 300,
                    BackgroundColor   = Color.Red,
                    ResourceUrl       = Application.Current.DirectoryInfo.Resource + "image.png",
                };
                scrollView.ContentContainer.Add(img);
            }

            {
                var img = new Image
                {
                    SizeHeight         = 300,
                    WidthSpecification = LayoutParamPolicies.MatchParent,
                    ResourceUrl        = "http://i.imgur.com/9f974SC.jpg",
                    // now it does not working, but NUI team will fix it
                    Aspect = Tizen.UIExtensions.Common.Aspect.AspectFill
                };
                img.ResourceReady += (s, e) =>
                {
                    Console.WriteLine($"Image Loaded - {img.LoadingStatus}");
                };
                scrollView.ContentContainer.Add(new Label {
                    Text = "AspectFill"
                });
                scrollView.ContentContainer.Add(img);
            }

            {
                var img = new Image
                {
                    SizeHeight         = 300,
                    WidthSpecification = LayoutParamPolicies.MatchParent,
                    ResourceUrl        = "http://i.imgur.com/9f974SC.jpg",
                    // now it does not working, but NUI team will fix it
                    Aspect = Tizen.UIExtensions.Common.Aspect.AspectFit
                };
                img.ResourcesLoaded += (s, e) =>
                {
                    Console.WriteLine($"Image Loaded - {img.LoadingStatus}");
                };
                scrollView.ContentContainer.Add(new Label {
                    Text = "AspectFit"
                });
                scrollView.ContentContainer.Add(img);
            }

            {
                var img = new Image
                {
                    SizeHeight         = 300,
                    WidthSpecification = LayoutParamPolicies.MatchParent,
                    ResourceUrl        = "http://i.imgur.com/9f974SC.jpg",
                    // now it does not working, but NUI team will fix it
                    Aspect = Tizen.UIExtensions.Common.Aspect.Fill
                };
                img.ResourcesLoaded += (s, e) =>
                {
                    Console.WriteLine($"Image Loaded - {img.LoadingStatus}");
                };
                scrollView.ContentContainer.Add(new Label {
                    Text = "Fill"
                });
                scrollView.ContentContainer.Add(img);
            }

            {
                var img = new Image
                {
                    ResourceUrl = Application.Current.DirectoryInfo.Resource + "animated2.gif",
                };
                img.SetIsAnimationPlaying(true);
                img.ResourcesLoaded += (s, e) =>
                {
                    // Aspect not apply before loaded image
                    Console.WriteLine($"Image Loaded");
                };
                scrollView.ContentContainer.Add(new Label {
                    Text = "Animated"
                });
                scrollView.ContentContainer.Add(img);
            }

            {
                var img = new Image
                {
                    ResourceUrl = Application.Current.DirectoryInfo.Resource + "animated2.gif",
                };
                img.SetIsAnimationPlaying(false);
                img.ResourcesLoaded += (s, e) =>
                {
                    // Aspect not apply before loaded image
                    Console.WriteLine($"Image Loaded");
                };
                scrollView.ContentContainer.Add(new Label {
                    Text = "SetIsAnimationPlaying(false)"
                });
                scrollView.ContentContainer.Add(img);
            }

            return(view);
        }