BitmapToRadBitmapImageConverter

2 posts, 1 answers
  1. Saykor
    Saykor avatar
    70 posts
    Member since:
    Feb 2011

    Posted 11 Oct 2014 Link to this post

    Hello,
    In this demo: http://demos.telerik.com/silverlight/#ImageEditor/Cropping you use BitmapToRadBitmapImageConverter. Can you please share the code for the converter?

    I suppose it is something like this:

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                var image = value as BitmapImage;
                if(image != null)
                    return new RadBitmap(image);

                return null;
            }

    But will be good to have the original code.

    Regards,
    Saykor
  2. Answer
    Petya
    Admin
    Petya avatar
    975 posts

    Posted 14 Oct 2014 Link to this post

    Hello Saykor,

    Here is the code of the converter from the demo in question:
    public class BitmapToRadBitmapImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            BitmapImage bitmapImage = value as BitmapImage;
            if (bitmapImage == null)
            {
                return null;
            }
            return ImageExampleHelper.GetRadBitmap(bitmapImage.UriSource.ToString(), new PngFormatProvider());
        }
     
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

     And this is the code of the GetRadBitmap() method in the helper class:
    public static RadBitmap GetRadBitmap(string resource, IImageFormatProvider provider)
      {
          using (Stream stream = Application.GetResourceStream(new Uri(resource, UriKind.RelativeOrAbsolute)).Stream)
          {
              return provider.Import(stream);
          }
      }

    I also wanted to mention that all demos are downloadable from your Telerik account here, so you can browse the code and try them out locally if you want to.

    Regards,
    Petya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top