This project is read-only.

SetSource in ExtendedImage

Oct 20, 2010 at 5:21 PM

Im trying to set the image to ExtendedImage. But it keep on throwing the NullException. 

here is the code. 

  Picture picture = mediaLib.GetPictureFromToken(queryStrings["token"]);
                try
                {
                    var stream = picture.GetImage();
                    
                    MessageBox.Show((stream == null).ToString()); // False here
                    image.SetSource(stream);

               }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

Coordinator
Oct 20, 2010 at 5:37 PM
Confusing, can you give me the information where this error occurs by
posting the stack trace.
Oct 20, 2010 at 5:59 PM

Sorry. My stupid mistake. 

As of now, I didn't get the exception but I didn't get any image as well.  I have build-in image control and your image container in Grid. I got the image in ImageControl but not in your image container.  Am I missing something? 

XAML

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="2*"/>
                <RowDefinition Height="2*"/>
            </Grid.RowDefinitions>
            <imgLib:ImageEditorContainer x:Name="imgContainer" Grid.Row="0" />
            <Image x:Name="imgControl" Grid.Row="1" />
        </Grid>

Attempt #1

MediaLibrary mediaLib = new MediaLibrary();
Picture picture = mediaLib.GetPictureFromToken(queryStrings["token"]);

var stream = picture.GetImage();
                    BitmapImage bitmap = new BitmapImage();
                    bitmap.SetSource(picture.GetImage());

                    ImageTools.ExtendedImage img = new ImageTools.ExtendedImage(bitmap.PixelWidth, bitmap.PixelHeight);
                    img.SetSource(stream);
                    imgContainer.Source = img;
                                        
                    imgControl.Source = bitmap;    

Attempt #2

 MediaLibrary mediaLib = new MediaLibrary();
                Picture picture = mediaLib.GetPictureFromToken(queryStrings["token"]);
                try
                {
                    var stream = picture.GetImage();
                    ImageTools.ExtendedImage img = new ImageTools.ExtendedImage();
                    img.SetSource(stream);
                    imgContainer.Source = img;

                    BitmapImage bitmap = new BitmapImage();                    
                    bitmap.SetSource(picture.GetImage());
                    imgControl.Source = bitmap;    
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

 

Coordinator
Oct 20, 2010 at 6:04 PM
Did you add the image decoders? When you want: add my in msn:
malignate@hotmail.de
Oct 20, 2010 at 6:17 PM

Thanks. I added you in MSN..

Nope. I didn't.. How can I add it? I tried as below but not working. 

 

  var stream = picture.GetImage();
                    ImageTools.ExtendedImage img = new ImageTools.ExtendedImage();

                    BmpEncoder encoder = new BmpEncoder();
                    encoder.Encode(img, stream);

                    img.SetSource(stream);
                    imgContainer.Source = img;

Oct 20, 2010 at 6:22 PM

I tried with Bmp Decoder as well. but it throws Overflow exception

Coordinator
Oct 20, 2010 at 6:30 PM
Got no invitation, you can send me your address, then I can add you to
help you with your problem.

Did you read the following article?
http://imagetools.codeplex.com/wikipage?title=Working%20with%20different%20image%20formats&referringTitle=Home
Oct 20, 2010 at 6:35 PM

Mine is mchlsync@gmail.com.. I'm in both MSN web and gtalk. 

I just tried adding BmpDecoder, PngDecoder, GifDecoder but all are not working in my sample. JpegEncoder is not available for Phone ..

 

Nov 15, 2010 at 1:04 PM

I am also having issues with how to use the image tools to load an image.

I started with the demo app code.

i made a simple silverlight app and added code from the demo app "editing" view as i need to make a simple form that allows a user to select an image and then crop it to select a persons face in the source picture.

even copying the sample i am having problems with the lines:


Container.Source = new ExtendedImage();
Container.Source.UriSource = new Uri("/Images/Penguins.jpg", UriKind.Relative);

no error is thrown and no image is shown!

when i try to load an image with the fileopendialog and look for the loading failed event i get an error that gives this:


{System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.Max(IEnumerable`1 source)
   at System.Linq.Enumerable.Max[TSource](IEnumerable`1 source, Func`2 selector)
   at ImageTools.ExtendedImage.Load(Stream stream)
   at ImageTools.ExtendedImage.<>c__DisplayClass18.<LoadAsync>b__17(Object objectState)} 
   System.SystemException {System.InvalidOperationException}

StackTrace = "   at System.Linq.Enumerable.Max(IEnumerable`1 source)\r\n  
at System.Linq.Enumerable.Max[TSource](IEnumerable`1 source, Func`2 selector)\r\n  
at ImageTools.ExtendedImage.Load(Stream stream)\r\n  
at ImageTools.ExtendedImage.<>c__DisplayClass18.<LoadAsyn...

 

but the same fileopen code in a different view / form works with the standard silverlight image control and BitmapImage class.

 

can someone make a small demo of doing this ?

the same UI as the image editor in the current demo but as a stand alone solution that shows how to load an image from a file into the edit container control.

the current demo solution is part of the source and that wants the code contracts to be downloaded and i do not want to mess with the source just to get an app working.

 

Coordinator
Nov 15, 2010 at 1:23 PM
Did you add the decoders?

http://imagetools.codeplex.com/wikipage?title=Working%20with%20different%20image%20formats&referringTitle=Home
Nov 15, 2010 at 8:08 PM

The sample code i started with had nothing like that.

I do not know if that was a bad sample or due to some changes they made or what....

in the sample they set the image to the "Pengins.jpg" that they added to the demo project.

all they did there was set the Uri to the filename.

that works here on the web site sample page.

does not work for me at home.

i will see if that is the problem tonight when i get home.

possibly the error i get is they are trying to use LINQ to objects to find a matching class to process the image?

and possibly the demo code needs to be updated to reflect this ??

 

Nov 15, 2010 at 8:11 PM

see this :

       #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Editing"/> class and loads a sample
        /// image that is edited by the editor container.
        /// </summary>
        public Editing()
        {
            InitializeComponent();

            SelectionModeComboBox.SelectedIndex = 2;

            Container.Source = new ExtendedImage();
            Container.Source.UriSource = new Uri("Images/Penguins.jpg", UriKind.Relative);
        }

in demo / views / editing.cs in the source in codeplex right now.

Nov 15, 2010 at 11:49 PM

OK looks like the demo had the code to add the decoders stashed in the app.xaml.cs file.

does the documentation say this is needed ?

I recall reading some stuff in the doc file but not this.

well at least now i can load an image and work on the next steps.

 

thanks.