Exception when loading image from website.

Thread is closed for posting
4 posts, 0 answers
  1. Mike
    Mike avatar
    5 posts
    Member since:
    Mar 2013

    Posted 16 Mar 2014 Link to this post

    I use webclient to download an image from a website and want to load it in the image editor.
    I get this exception in the output window though the app does not crash. The image is not shown at this point. When I use a tool i.e. resize tool and click save the image is displayed just fine

    System.Windows.Data Error: 'MS.Internal.Data.DynamicValueConverter' converter failed to convert value 'System.Object[]' (type 'System.Object[]'); BindingExpression: Path='' DataItem='System.Object[]' (HashCode=6421510); target element is 'Telerik.Windows.Controls.RadImageEditor' (Name='imageEditor'); target property is 'Source' (type 'System.Windows.Media.ImageSource').. System.InvalidOperationException: Can't convert type System.Object[] to type System.Windows.Media.ImageSource.
    at MS.Internal.Data.DefaultValueConverter.Create(Type sourceType, Type targetType, Boolean targetToSource)
    at MS.Internal.Data.DynamicValueConverter.EnsureConverter(Type sourceType, Type targetType)
    at MS.Internal.Data.DynamicValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
    at System.Windows.Data.BindingExpression.ConvertToTarget(Object value).

    any help is appreciated


  2. Mike
    Mike avatar
    5 posts
    Member since:
    Mar 2013

    Posted 16 Mar 2014 Link to this post

    Here is the function I am using
    void loadImage(string imagePath)
    ​ WebClient webClientImgDownloader = new WebClient();
    webClientImgDownloader.OpenReadCompleted += new OpenReadCompletedEventHandler(webClientImgDownloader_OpenReadCompleted);
    webClientImgDownloader.OpenReadAsync(new Uri(imagePath, UriKind.Absolute));
    void webClientImgDownloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    BitmapImage bitmap = new BitmapImage();

                imageEditor.Source = bitmap;
  3. Mike
    Mike avatar
    5 posts
    Member since:
    Mar 2013

    Posted 16 Mar 2014 Link to this post

     Found a different solution

    public static BitmapImage image;

    to the page with the editor

    before navigating to the page rather than loading the image explicitly using WebClient I do

    imgEditPage.image=new BitmapImage(new Uri(imagePath,UriKind.Absolute));

    that seems to work 98% of the time. Only if the image takes a little longer to load the editor shows a black background. If you have a solution that works better I am all ears :)
  4. Victor
    Victor avatar
    1358 posts

    Posted 17 Mar 2014 Link to this post

    Hi Mike,

    Thanks for writing.
    I think the best way to make your case work is to have a view model with a property named Image or Bitmap for example. It should be null by default. Then, you bind RadImageEditor's Source property to your Bitmap/Image property. When you navigate to your editor page, if your view model property is null and the image editor will display nothing. Finally when the web client finishes downloading the bitmap, you update your view model and the image editor should refresh itself.

    Since it is possible that the image is not yet downloaded when you navigate to the editor page you can display a busy indicator until the download finishes.

    Please write again if you need further assistance.


    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

Back to Top