/// <summary> /// Method to convert string path of the picture into bitmap image. /// </summary> /// <param name="value">The binding object path of the picture.</param> /// <param name="targetType">The target type for binding.</param> /// <param name="parameter">Parameter for convert.</param> /// <param name="culture">The culture to convert.</param> /// <returns>A bitmap image for image binding.</returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // The value parameter is the data from the source object. string filename = (string)value; //BitmapImage bmp = new BitmapImage(new Uri(filename)); //bmp.BeginInit(); //bmp.BaseUri = new Uri(filename); //bmp.EndInit(); BitmapImage bmp = PictureMemoryCache.Set(filename, Width, false, new TimeSpan(), true); try { //if (Extensions.Contains(ext.ToLower())) //{ // if (parameter != null) // { // Width = int.Parse((string)parameter); // } // bmp = PictureMemoryCache.Set(filename, Width, false); //} //else //{ // bmp = ShellEx.GetBitmapFromFilePath(filename, IconSize).ToBitmapImage(); //} } catch { } return(bmp); }
/// <summary> /// Method to convert string path of the picture into bitmap image. /// </summary> /// <param name="value">The binding object path of the picture.</param> /// <param name="targetType">The target type for binding.</param> /// <param name="parameter">Parameter for convert.</param> /// <param name="culture">The culture to convert.</param> /// <returns>A bitmap image for image binding.</returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // The value parameter is the data from the source object. string filename = (string)value; string ext = Path.GetExtension(filename); BitmapImage bmp = null; try { if (Extensions.Contains(ext.ToLower())) { if (parameter != null) { Width = int.Parse((string)parameter); } bmp = PictureMemoryCache.Set(filename, Width, false); } else { bmp = ShellEx.GetBitmapFromFilePath(filename, IconSize).ToBitmapImage(); } } catch (Exception e) { log.Debug(e.Output(), e); } return(bmp); }