private static BitmapImage ReturnImageBySize(TLPhoto photo, double width) { TLPhotoSize size = null; var sizes = photo.Sizes.OfType <TLPhotoSize>(); foreach (var photoSize in sizes) { if (size == null || Math.Abs(width - size.W.Value) > Math.Abs(width - photoSize.W.Value)) { size = photoSize; } } if (size != null) { var location = size.Location as TLFileLocation; if (location != null) { var timer = Stopwatch.StartNew(); var image = DefaultPhotoConverter.ReturnImage(timer, location); if (image != null) { return(image); } } } return(null); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var timer = Stopwatch.StartNew(); var photoSize = value as TLPhotoSize; if (photoSize != null) { var location = photoSize.Location as TLFileLocation; if (location != null) { return(DefaultPhotoConverter.ReturnImage(timer, location)); } } return(null); }