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 }
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); }
public bool Match(Image<Gray,Byte> IrisCode1,Image<Gray,Byte> IrisCode2) { Image<Gray, Byte> XORImage = new Image<Gray, Byte>(360, IrisConstants.imageHeight); XORImage.SetValue(0.0); CvInvoke.cvXor(IrisCode1,IrisCode2, XORImage, IntPtr.Zero); Xorsum=0; for(int w=0;w<360;w++) { for(int h=0;h<240;h++) { if(XORImage.Data[h,w,0]==255) { Xorsum++; } } } hammingDistance=(double)Xorsum/86400; if (hammingDistance > 0.29) return false; else return true; }
/// <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); }*/ }
/// <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! }
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); }
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"); } }; imgAddToCart.GestureRecognizers.Add(atcTapGestureRecognizer); // Create tap event for ImageButton var atslTapGestureRecognizer = new TapGestureRecognizer(); atslTapGestureRecognizer.Tapped += async (s, e) => { //Add to cart table in db var res = await DisplayAlert("Add to Shopping List?", "Do you want to add the item '" + _itemName + "' to your Shopping List?", "Yes", "No"); if (res) { //execute query -> add to shopping list InsertIntoShoppingList(); await DisplayAlert ("Added To Shopping List", "'" + _itemName + "' was added to your Shopping List", "Continue Browsing"); } }; imgAddToShoppingList.GestureRecognizers.Add(atslTapGestureRecognizer); Content = new StackLayout { BackgroundColor = Color.FromHex ("#E4E4E4"), VerticalOptions = LayoutOptions.FillAndExpand, Children = { new StackLayout { HorizontalOptions = LayoutOptions.FillAndExpand, Children = { new StackLayout { Spacing = 0, HorizontalOptions = LayoutOptions.StartAndExpand, Children = { itemBannerImage, separator1, separator2, separator3 } } } }, new StackLayout { Padding = new Thickness(20, 0, 20, 20), Orientation = StackOrientation.Horizontal, Children = { new StackLayout { HorizontalOptions = LayoutOptions.StartAndExpand, Children = { lblItemName, lblDiscountedPrice, lblPrice, lblPriceDifference } }, new StackLayout { Padding = new Thickness(10, 20, 0, 0), Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.End, Children = { imgAddToCart, imgAddToShoppingList } } } }, new StackLayout { Orientation = StackOrientation.Vertical, Padding = new Thickness(20, 0), Children = { lblItemDescription } } } }; }
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); }