private void PrepareImages() { _rows.Clear(); _items.Clear(); _layoutRoot.Children.Clear(); if (Source == null) return; foreach (var bitmapImage in Source) { var image = new Image(); image.Stretch = Stretch.UniformToFill; image.Source = bitmapImage; var item = new MosaicItem1(image, new Size(bitmapImage.PixelWidth, bitmapImage.PixelHeight)); _items.Add(item); _layoutRoot.Children.Add(image); } }
private void PlaceItem(MosaicItem1 item, Rect targetRect) { item.ComputedLocation = new Point(targetRect.X, targetRect.Y); Canvas.SetLeft(item.Image, targetRect.X); Canvas.SetTop(item.Image, targetRect.Y); }
private void FitToRow(MosaicItem1 item, double rowHeight) { var scale = rowHeight / item.ComputedSize.Height; item.Image.Width *= scale; item.Image.Height *= scale; item.ComputedSize = new Size(item.Image.Width, item.Image.Height); }
private void MeasureItem(MosaicItem1 item) { if (item.OriginalSize.Width > MaxImageSize || item.OriginalSize.Height > MaxImageSize) { var scale = MaxImageSize / (item.OriginalSize.Width > item.OriginalSize.Height ? item.OriginalSize.Width : item.OriginalSize.Height); item.Image.Width = item.OriginalSize.Width * scale; item.Image.Height = item.OriginalSize.Height * scale; } else { item.Image.Width = item.OriginalSize.Width; item.Image.Height = item.OriginalSize.Height; } item.ComputedSize = new Size(item.Image.Width, item.Image.Height); }
private Rect ComputeItemLocation(MosaicItem1 item, Rect targetRect) { return new Rect(targetRect.X, targetRect.Y, item.ComputedSize.Width, item.ComputedSize.Height); }