This is a migrated thread and some comments may be shown as answers.

BitmapToRadBitmapImageConverter

1 Answer 360 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Saykor
Top achievements
Rank 2
Saykor asked on 11 Oct 2014, 01:24 PM
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

1 Answer, 1 is accepted

Sort by
0
Accepted
Petya
Telerik team
answered on 14 Oct 2014, 05:29 PM
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.

 
Tags
ImageEditor
Asked by
Saykor
Top achievements
Rank 2
Answers by
Petya
Telerik team
Share this question
or