当前位置: 首页>>代码示例>>C#>>正文


C# Image.SetValue方法代码示例

本文整理汇总了C#中System.Image.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Image.SetValue方法的具体用法?C# Image.SetValue怎么用?C# Image.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Image的用法示例。


在下文中一共展示了Image.SetValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: viewcellitems

        public viewcellitems()
        {
            #region creation de la view
            Nom_produit = new Label () {
                FontAttributes = FontAttributes.Bold,
                FontSize = 20,
                TextColor = Color.Black
            };
            Nom_produit.SetBinding (Label.TextProperty, "Nom_produit");

            var IconAnzeige = new Image ();
            IconAnzeige.SetBinding (Image.SourceProperty, new Binding ("IconName", BindingMode.OneWay, new StringToImageConverter ()));
            IconAnzeige.HeightRequest = 50;
            IconAnzeige.HorizontalOptions = LayoutOptions.EndAndExpand;
            IconAnzeige.VerticalOptions = LayoutOptions.End;

            Detail = new Label () {
                FontAttributes = FontAttributes.Bold,
                FontSize = 16,
                TextColor = Color.FromHex ("ff3498dc")
            };
            Detail.SetBinding (Label.TextProperty, "Detail");

            #region grid
            var rowdefdef = new RowDefinition {
                Height = GridLength.Auto,

            };
            var columndef = new ColumnDefinition {
                Width = GridLength.Auto
            };

            var grid = new Grid {
                HorizontalOptions = LayoutOptions.Fill,
                Padding = 5
            };
            grid.RowDefinitions.Add (rowdefdef);
            grid.ColumnDefinitions.Add (columndef);

            Nom_produit.SetValue (Grid.ColumnProperty, 0);
            Nom_produit.SetValue (Grid.RowProperty, 0);
            grid.Children.Add (Nom_produit);

            Detail.SetValue (Grid.ColumnProperty, 0);
            Detail.SetValue (Grid.RowProperty, 1);
            grid.Children.Add (Detail);

            IconAnzeige.SetValue (Grid.ColumnProperty, 1);
            IconAnzeige.SetValue (Grid.RowProperty, 0);
            grid.Children.Add (IconAnzeige);

            #endregion

            View = grid;

            #endregion
        }
开发者ID:EricPucho,项目名称:Listview_with_checkbox_XF,代码行数:57,代码来源:viewcellitems.cs

示例2: TestSetStringValue

		public void TestSetStringValue ()
		{
			var image = new Image ();
			image.SetValue (Image.SourceProperty, "foo.png");		
			Assert.IsNotNull (image.Source);
			Assert.That (image.Source, Is.InstanceOf<FileImageSource> ());
			Assert.AreEqual ("foo.png", ((FileImageSource)(image.Source)).File);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:8,代码来源:ImageSourceTests.cs

示例3: testLazyMemCache

        /// <summary>
        /// Creates and tests lazy memory cache where elements are constructed on demand and evicted based on LRU strategy only if the RAM usage above specified limits.
        /// </summary>
        static void testLazyMemCache()
        {
            ComputerInfo computerInfo = new ComputerInfo(); //reference to Microsoft.VisualBasic assembly.

            //construction
            var memCache = new LazyMemoryCache<int, Image<Gray, int>>
              (
               (currentSize) =>
                {
                    var occupied = computerInfo.TotalPhysicalMemory - computerInfo.AvailablePhysicalMemory;
                    var occupiedPercentage = (float)occupied / computerInfo.TotalPhysicalMemory;

                    //WATCH OUT! You can get OutOfMemoryException although the RAM is not full:
                       //when creating fields with zeros I assume there are some OS optimizations like block sharing
                       //if you compile this as 32-bit (when it consumes 2 GiB it will throw OutOfMemoryException)
                    if (occupiedPercentage > 0.45)
                       return true;

                    return false;
                },

                (img) => (ulong)(img.Stride * img.Height),

                //set false to not to call GC.Collect() when an item is evicted => may fill more RAM than it has been set, but shortens delays caused by GC
                forceCollectionOnRemoval: true
               );

            Console.WriteLine("Filling lazy cache (with constructors)...");
            const int MAX_KEY = 100;
            //adding elements (you can also use stream as IEnumerable to populate cache)
            for (int key = 0; key <= MAX_KEY; key++)
            {
                memCache.AddOrUpdate(key, () =>
                {
                    //simulate getting image from a disc (slow operation)
                    var img = new Image<Gray, int>(640, 480);
                    img.SetValue(key);
                    Thread.Sleep(60);

                    return img;
                },
                (img) => { img.Dispose(); });
            }

            //accessing elements (run Task Manager to see memory allocation!)
            Console.WriteLine("Accessing elements (run Task Manager to see memory allocation!):");
            Random rand = new Random();
            while (!Console.KeyAvailable)
            {
                var key  = rand.Next(0, MAX_KEY + 1);
                ILazy<Image<Gray, int>> lazyVal;
                memCache.TryGetValue(key, out lazyVal);

                Console.ForegroundColor = lazyVal.IsValueCreated ? ConsoleColor.Green: ConsoleColor.Red;
                Image<Gray, int> val = null;
                var elapsed = Diagnostics.MeasureTime(() =>
                {
                    val = lazyVal.Value;
                });

                Console.Write("\r Accessing {0}. Access time: {1} ms.", key, elapsed);
            }

            //accessing elements (run Task Manager to see memory allocation!)
            /*foreach (var item in memCache)
            {
                 var lazyVal = item.Value;

                Console.WriteLine(lazyVal.Value);
                Console.WriteLine(memCache.HardFaults);
            }*/
        }
开发者ID:remingtonsteel,项目名称:accord-net-extensions,代码行数:75,代码来源:Program.cs

示例4: testLRUCache

        /// <summary>
        /// Creates a new instance of LRU cache where elements are evicted based on least frequently usage.
        /// </summary>
        static void testLRUCache()
        {
            ComputerInfo computerInfo = new ComputerInfo(); //reference to Microsoft.VisualBasic assembly.

            var lru = new LRUCache<int, Image<Gray, byte>>(
                                                    (currentSize) =>
                                                    {
                                                        var occupied = computerInfo.TotalPhysicalMemory - computerInfo.AvailablePhysicalMemory;
                                                        var occupiedPercentage = (float)occupied / computerInfo.TotalPhysicalMemory;

                                                        if (occupiedPercentage > 0.85)
                                                            return true;

                                                        return false;
                                                    },
                                                    (img) => (ulong)(img.Stride * img.Height));

            lru.OnRemoveItem += lru_OnRemoveItem;

            /***************** add some elements ****************/
            var image = new Image<Gray, byte>(5 * 1024 * 1024, 1, 0);
            image.SetValue(5 % 256);
            lru.Add(1, image);

            image = new Image<Gray, byte>(5 * 1024 * 1024, 1, 0);
            image.SetValue(5 % 256);
            lru.Add(1, image);
            /***************** add some elements ****************/

            List<Image<Gray, byte>> a = new List<Image<Gray, byte>>();

            Random rand = new Random();

            int i = 0;
            while (i < 10000)
            {
                image = new Image<Gray, byte>(1024 * 1024, 1, 0);
                image.SetValue(i % 256);
                lru.Add(i, image);

                //Thread.Sleep(1);
                Console.WriteLine(computerInfo.AvailablePhysicalMemory / 1024 / 1024);
                i++;
            }

            //discover more properties and methods!
        }
开发者ID:remingtonsteel,项目名称:accord-net-extensions,代码行数:50,代码来源:Program.cs

示例5: calculate

        private static void calculate(MathOps mathOpIdx, IImage src1, IImage src2, IImage dest, Image<Gray, byte> mask = null)
        {
            Debug.Assert(src1.ColorInfo.Equals(src2.ColorInfo) && src1.Size.Equals(src2.Size));

            if (mask == null)
            {
                mask = new Image<Gray, byte>(dest.Width, dest.Height);
                mask.SetValue(new Gray(255));
            }

            var mathOperationOnTypes = mathOperatorFuncs[(int)mathOpIdx];

            MathOpFunc mathOpFunc = null;
            if (mathOperationOnTypes.TryGetValue(src1.ColorInfo.ChannelType, out mathOpFunc) == false)
                throw new Exception(string.Format("Math operation {0} can not be executed on an image of type {1}", mathOpIdx.ToString(), src1.ColorInfo.ChannelType));

            var proc = new ParallelProcessor<bool, bool>(dest.Size,
                                                            () =>
                                                            {
                                                                return true;
                                                            },
                                                            (bool _, bool __, Rectangle area) =>
                                                            {
                                                                var src1Patch = src1.GetSubRect(area);
                                                                var src2Patch = src2.GetSubRect(area);
                                                                var destPatch = dest.GetSubRect(area);
                                                                var maskPatch = mask.GetSubRect(area);

                                                                mathOpFunc(src1Patch, src2Patch, destPatch, maskPatch);
                                                            }
                                                            /*,new ParallelOptions { ForceSequential = true}*/);

            proc.Process(true);
        }
开发者ID:remingtonsteel,项目名称:accord-net-extensions,代码行数:34,代码来源:MathOperations.cs

示例6: ItemDetailsPage

        public ItemDetailsPage(int itemID)
        {
            Title = "Item Details";

            _itemID = itemID;

            // Get item information from database
            var db = DependencyService.Get<ISQLite> ().GetConnection ();
            var table = db.Query<ItemDetails> ("SELECT * FROM ItemDetails WHERE ID = ?", itemID);
            foreach (var item in table) {
                _itemName = item.Name;
                _itemPrice = item.ItemPrice;
                _itemDiscountedPrice = item.DiscountedItemPrice;
                _itemBannerImage = ImageSource.FromStream (() => new MemoryStream (item.BannerImage));
                //TODO: Add Description
            }

            Label lblItemName = new Label {
                Text = _itemName,
                TextColor = Color.Black,
                FontSize = 30
            };

            Image itemBannerImage = new Image ();
            itemBannerImage.SetValue (Image.SourceProperty, _itemBannerImage);
            itemBannerImage.HorizontalOptions = LayoutOptions.FillAndExpand;

            BoxView separator1 = new BoxView {
                BackgroundColor = Color.FromHex("#555555"),
                HeightRequest = 1,
                WidthRequest = 360,
                HorizontalOptions = LayoutOptions.Center
            };
            BoxView separator2 = new BoxView {
                BackgroundColor = Color.FromHex("#999999"),
                HeightRequest = 1,
                WidthRequest = 360,
                HorizontalOptions = LayoutOptions.Center
            };
            BoxView separator3 = new BoxView {
                BackgroundColor = Color.FromHex("#B6B6B6"),
                HeightRequest = 1,
                WidthRequest = 360,
                HorizontalOptions = LayoutOptions.Center
            };

            Image itemImage = new Image();
            itemImage.SetBinding(Image.SourceProperty, "Image");
            itemImage.WidthRequest = 70;

            Image imgAddToCart = new Image();
            imgAddToCart.Source = "addtocart.png";
            imgAddToCart.WidthRequest = 50;
            imgAddToCart.HeightRequest = 50;

            Image imgAddToShoppingList = new Image();
            imgAddToShoppingList.Source = "addtoshoppinglist.png";
            imgAddToShoppingList.WidthRequest = 50;
            imgAddToShoppingList.HeightRequest = 50;

            Label lblPrice = new Label {
                Text = "Original Price: " + _itemPrice.ToString("C2"),
                TextColor = Color.Black
            };

            Label lblDiscountedPrice = new Label {
                Text = "Current Price: " + _itemDiscountedPrice.ToString("C2"),
                FontAttributes = FontAttributes.Bold,
                TextColor = Color.Black
            };

            double _ItemPriceDifference = _itemPrice - _itemDiscountedPrice;

            Label lblPriceDifference = new Label {
                Text = "You Save: " + _ItemPriceDifference.ToString("C")
            };

            Label lblItemDescription = new Label();
            lblItemDescription.SetBinding(Label.TextProperty, "ItemDescription");
            lblItemDescription.Text = "This is a quality product from the finest ranges in Australia. Only in the lush outback can such luxurious products thrive, and this" +
                " is why we take pride in our product. Our product has zero preservatives, no added colours or flavours, and is great for kids";
            lblItemDescription.TextColor = Color.Black;
            lblItemDescription.FontSize = 16;

            if (_itemPrice.CompareTo (_itemDiscountedPrice) <= 0) {
                lblPriceDifference.TextColor = Color.FromHex ("#E4E4E4");
                lblPrice.TextColor = Color.FromHex ("#E4E4E4");
            } else {
                lblPriceDifference.TextColor = Color.Blue;
            }

            // Create tap event for ImageButton
            var atcTapGestureRecognizer = new TapGestureRecognizer();
            atcTapGestureRecognizer.Tapped += async (s, e) => {
                //Add to cart table in db
                var res = await DisplayAlert("Add to cart?", "Do you want to add the item '" + _itemName + "' to your cart?", "Yes", "No");
                if (res) {
                    InsertIntoShoppingCart();//execute query -> add to cart
                    await DisplayAlert ("Added To Cart", "'" + _itemName + "' was added to your cart", "Continue Shopping");
                }
//.........这里部分代码省略.........
开发者ID:jackphilippi,项目名称:SmartCart,代码行数:101,代码来源:ItemDetailsPage.cs

示例7: SetupBackgroundGrid

        private void SetupBackgroundGrid()
        {
            _backgroundGrid = new Grid {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                RowDefinitions = {
                    new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }
                }
            };

            // Background.jpg: Macro Background Print 9 by Jason Weymouth Photography (https://www.flickr.com/photos/jason_weymouth/)
            // License: Attribution-ShareAlike 2.0 Generic (https://creativecommons.org/licenses/by-sa/2.0/)
            // Additional license information can be found in Background.jpg.license in root of repository.
            Image backgroundImage = new Image { Source = "Background.jpg", HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, Aspect = Aspect.AspectFill, Opacity = 1 };
            backgroundImage.SetValue(Grid.RowSpanProperty, 1);
            backgroundImage.SetValue(Grid.ColumnSpanProperty, 1);
            _backgroundGrid.Children.Add(backgroundImage);

            StackLayout mask = new StackLayout { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.Black, Opacity = 0.1 };
            mask.SetValue(Grid.RowSpanProperty, 1);
            mask.SetValue(Grid.ColumnSpanProperty, 1);
            _backgroundGrid.Children.Add(mask);
        }
开发者ID:rringham,项目名称:XamarinOffice365,代码行数:23,代码来源:Office365DashboardPage.cs


注:本文中的System.Image.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。