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

Exception when loading image from website.

3 Answers 49 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mike
Top achievements
Rank 1
Mike asked on 16 Mar 2014, 05:01 AM
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

thanks

Mike

3 Answers, 1 is accepted

Sort by
0
Mike
Top achievements
Rank 1
answered on 16 Mar 2014, 05:04 AM
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();
bitmap.SetSource(e.Result);

            imageEditor.Source = bitmap;
}
0
Mike
Top achievements
Rank 1
answered on 17 Mar 2014, 04:20 AM
 Found a different solution

added
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));
NavigationService.Navigate(...);

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 :)
0
Victor
Telerik team
answered on 17 Mar 2014, 07:34 AM
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.

Regards,
Victor
Telerik
 

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

 
Tags
ImageEditor
Asked by
Mike
Top achievements
Rank 1
Answers by
Mike
Top achievements
Rank 1
Victor
Telerik team
Share this question
or