This project is read-only.

Error at using ExtendedImage to set the Source of a Silverlight Image element

Nov 22, 2010 at 3:29 PM

Hi,

I'm using ExtendedImage to set the Source of a Silverlight Image element, using the following code:

<Image Name="imgUpload" Margin="0,20,0,0" Stretch="None"/>
<HyperlinkButton Content="Upload" HorizontalAlignment="Left" Name="hbUpload" VerticalAlignment="Top" Click="hbUpload_Click" />


private void hbUpload_Click(object sender, RoutedEventArgs e)
{
    OpenFileDialog fileDialog = new OpenFileDialog();
    fileDialog.Multiselect = false;

    // Define the filter to load all format that can be handled by image tools.
    fileDialog.Filter = "Image Files (*.jpg;*.png;*gif)|*.jpg;*.png;*.gif";

    if (fileDialog.ShowDialog() == true)
    {
        ImageTools.IO.Decoders.AddDecoder<ImageTools.IO.Png.PngDecoder>();

        using (Stream stream = fileDialog.File.OpenRead())
        {
            ExtendedImage extImage = new ExtendedImage();
            extImage.SetSource(stream);
            this.imgUpload.Source = extImage.ToBitmap();
        }
    }
}

Using this code the following error occurs: Precondition failed: image.IsFilled  Image has not been loaded.
Parameter name: Image has not been loaded.

I have added the following references: ImageTools, ImageTools.Controls, ImageTools.Filtering, ImageTools.IO.Gif, ImageTools.IO.Jpeg, ImageTools.IO.PNG, ImageTools.Utils.

What am I doing wrong?

Thx,
Danny

Nov 23, 2010 at 7:39 AM

Hi,

I have also tested it with your AnimatedImage and ImageEditorContainer controls, using the following code:

<it:AnimatedImage Name="imgUpload" Margin="0,20,0,0" Stretch="None"/>
or
<it:ImageEditorContainer Name="imgUpload" Margin="0,20,0,0" Stretch="None"/> 

this.imgUpload.Source = extImage;

In this case I do not get any error, but the Image is not showing at all... it looks like nothing happens.

Anobody?

Thx,
Danny

Nov 23, 2010 at 8:04 AM
The image is loading asynchronously. Can u use the loadingFailed evfent
to get information why an image could not be loaded.

Did you register the decoders?

http://imagetools.codeplex.com/wikipage?title=Working%20with%20different%20image%20formats&referringTitle=Home

Because of time the documentation is very bad at the moment. Sorry for that.
Nov 23, 2010 at 8:42 AM

Hi,

Thanks for your reply. I am handling the LoadingFailed and LoadingCompleted events now and the LoadingFailed event is fired with the following error:
System.InvalidOperationException: Cannot read from the stream.
   at ImageTools.ExtendedImage.Load(Stream stream)
   at ImageTools.ExtendedImage.<>c__DisplayClass18.<LoadAsync>b__17(Object objectState)

I am trying to load one of the Microsoft Windows sample images (Blue Hills, Sunset, etc.)

I have registered all available Decoders !

Any suggestions?

Thx,
Danny

Nov 23, 2010 at 9:04 AM

Probably you dont have reading permissions on the folder. The exception says that the CanRead property of your stream is false.

Nov 23, 2010 at 9:31 AM

Hi,

When I use the following code, to set the JPG file as the Source of the Image, without using ImageTools, I do not get any exception. So I think that reading permissions is the problem.

OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Multiselect = false;

// Define the filter to load all format that can be handled by image tools.
fileDialog.Filter = "Image Files (*.jpg;*.png;*gif)|*.jpg;*.png;*.gif";

if (fileDialog.ShowDialog() == true)
{
    using (Stream stream = fileDialog.File.OpenRead())
    {
        BitmapImage image = new BitmapImage();
        image.SetSource(stream);
        this.imgUpload.Source = image;
    }
}
Nov 23, 2010 at 9:44 AM

Which version do you use?

Did you compare your code which the code of the demo application that is part of source control?

 

When you want: Send me your project to sebastianstehle@gmx.de