×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Apr 2014
    Posts
    7

    GifRenderer ArgumentException: Value does not fall within the expected range

    Hi
    I have a problem with GifRenderer class.
    My scope is generate an animated gif starting from a list of png images stored in isolated storage of app and then save it and share it.
    When in my code I call GifRenderer.RenderAsync method, I have an ArgumentException, Value does not fall within the expected range, as you can see in following VB code.
    Where am I doing wrong?

    Code:
    Dim images = New List(Of IImageProvider)
    Dim image As Picture
    
    Try
        For Each fileName In fileNames
            images.Add(New StorageFileImageSource(Await StorageFile.GetFileFromPathAsync(IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, fileName))))
        Next
    
        Dim info = Await images(0).GetInfoAsync()
        Using renderer = New GifRenderer()
            renderer.Size = info.ImageSize
            renderer.Sources = images
            renderer.Duration = 1000
            Dim gifBuffer = Await renderer.RenderAsync()
            Dim stream = gifBuffer.AsStream()
    
            Using library = New MediaLibrary()
                Dim filename = String.Format("{0}+{1}.gif", IO.Path.GetFileNameWithoutExtension(fileNames(0)), fileNames.Count)
                image = library.SavePicture(IO.Path.GetFileName(filename), stream)
            End Using
        End Using
    
        Dim task = New ShareMediaTask()
        task.FilePath = image.GetPath()
        task.Show()
    Catch ex As Exception
        Debug.WriteLine(ex)
        'renderer.RenderAsync() ->
        'System.ArgumentException: Value does not fall within the expected range.
        ' at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
        ' at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        ' at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
        ' at WP8.App.VB$StateMachine_0_ShareAnimation.MoveNext()
    End Try

  2. #2
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    526

    Re: GifRenderer ArgumentException: Value does not fall within the expected range

    I'm not entirely certain if that the cause and I hope you forgive me for pasting C# code but it's what I have available right now. When I set the values in the GifRenderer's constructor I have to set the repeatcount. This is not set in your example and might be the reason for the issue. In general I would try to set as much as possible in the constructor.

    Here is a code sample that is taken directly from one of my projects which works:

    Code:
    IList<IImageProvider> sources = new List<IImageProvider>();
                foreach(WriteableBitmap bmp in mImgList)
                {
                    sources.Add(new BitmapImageSource(bmp.AsBitmap()));
                }
    
                using (GifRenderer renderer = new GifRenderer(sources, 333, 0))
                {
                    var buffer = await renderer.RenderAsync();
    
                    Windows.Storage.StorageFile sf = await ApplicationData.Current.LocalFolder.CreateFileAsync("img.gif", CreationCollisionOption.ReplaceExisting);
                    using(IRandomAccessStream stream = await sf.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        await stream.WriteAsync(buffer);
                    }
                }
    I'm using Images that were taken directly from the Camera so I'm using WritableBitmap there but it should work with the way you load your images just as well. Let me know if that helps you - otherwise I'll try to reproduce your issue in a sample project.

  3. #3
    Registered User
    Join Date
    Apr 2014
    Posts
    7

    Re: GifRenderer ArgumentException: Value does not fall within the expected range

    Unfortunately the problem is not repeatcount, I changed my code with this Using renderer = New GifRenderer(images, 1000, 0), I also tryed passing 1 instead of 0 at last parameter, but nothing changed. For test, I changed images list initialization using writablebitmaps popolated by isolated storage stream, but again, same exception.
    I also tryed using GifRenderer with single image, and I obtain always same exception.

    Don't worry for c#, all VB.NET developers must know also c# ;D

    Thank you

  4. #4
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    526

    Re: GifRenderer ArgumentException: Value does not fall within the expected range

    Perhaps it's an issue with the ImageSize parameter? I never tried rendering with it. If you're not resizing them you might want to try rendering without the size set (or try it just to find out if it's the cause of the issue you're seeing)..

  5. #5
    Registered User
    Join Date
    Apr 2014
    Posts
    7

    Re: GifRenderer ArgumentException: Value does not fall within the expected range

    Again no, the problem is not in image size. In my tests I have also tried using jpegrenderer, in this case I have no error, this means that the error is in the use of gifrenderer.I finished my immagination, gifrenderer have few parameters, and I have tried all possible combinations.
    Do you have any other idea?

  6. #6
    Registered User
    Join Date
    Apr 2014
    Posts
    7

    Re: GifRenderer ArgumentException: Value does not fall within the expected range

    Finally I find the origin of my problem, for a mysterious reason, nuget has linked the WinRT version of the library to my project, after I removed and re aded it,all work perfectly.

    Now the question is, there is a method for save the resultant image in "saved library"? I want partecipate to this DVLUP challenge, but I don't find any method for save an image different to jpg in phone library, as called for in the requirements of the challenge.

  7. #7
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    526

    Re: GifRenderer ArgumentException: Value does not fall within the expected range

    Curious issue, anything out of the ordinary with your project (e.g. Portable Class Library, etc.) other than it being a VB.Net project? Would be great to know if that happens in all VB.Net projects - if you find the time to test if Nuget always adds the wrong binaries that would be great. Happy to know that you were able to fix your issue

    WP8.0 does not support saving another format then JPEG to Saved Pictures. What you can do however is to save a JPEG file of one of your frames there and allow people to watch the animated GIF using the Rich Media Extensibility of the pictures Hub: http://msdn.microsoft.com/en-us/libr...vs.105%29.aspx which will link the JPEG to your App so that the user can open/view it there.

  8. #8
    Registered User
    Join Date
    Apr 2014
    Posts
    7

    Re: GifRenderer ArgumentException: Value does not fall within the expected range

    The project is a simple Windows Phone Application (silverlight), but the ViewModel is an external Portable Class Library that use MVVM Cross Library for porting the same app also in Android and iOS. In my tests I also created a new simple Windows Phone Application, and I have always the same error, also in this project the reference is of the wrong type, but removing e adding it again, solve the problem.
    I'm really amazed, I can not imagine how this could happen, the important is that we have found a solution.

    Thanks for the tip for saving gif, unfortunately this solution does not work for me, my app is not a real picture viewer, the gif is created from images taken from the web which represent hourly weather forecasts, the idea was to be able to share the animation of the forecasts, but if I can not save the gif in the library of the phone, I can not use ShareMediaTask. At this point I think I'd better save the gif on OneDrive and use the ShareLinkTask, hoping that this solution is still valid for the purposes of the challenge.

    Thank you again for the help

  9. #9
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    526

    Re: GifRenderer ArgumentException: Value does not fall within the expected range

    Thanks for testing the issue.

    As for the the integration with the Pictures Hub. You are already creating a GIF image. Instead of saving it to the MediaLibrary you only save one frame to the library and save the GIF to your local storage (IsolatedStorage). When the user then opens the Image through the Rich Media Extensibility you open a page that contains a WebView which links to the local image. I can post demo code on how to load such an image to a WebView in the evening when I get home. That way it can be played back on the device. As for sharing it via OneDrive - that's definitely a good idea. The important part for the challenge though seems to be the ability to find it in the MediaLibrary and launch it from there.

  10. #10
    Registered User
    Join Date
    Apr 2014
    Posts
    7

    Re: GifRenderer ArgumentException: Value does not fall within the expected range

    Oh yes, open the gif in a webview is a great idea, simple and quick to add to my app, in this mode I respect the challenge requirements without upsetting original goal of the feature

    If you have already an example, I'm happy to see it
    Thank you again

  11. #11
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    526

    Re: GifRenderer ArgumentException: Value does not fall within the expected range

    I somehow remembered that as more complicated than it was. I have a browser control on the page and simply point it to the GIF file in the root of my IsolatedStorage and point it to the file using the following line:

    Code:
    browser.Navigate(new Uri("/img.gif", UriKind.Relative));
    So nothing fancy but it plays the GIF - although with a white background. So you might want to generate a simplistic HTML page to go with the image and open that one.

  12. #12
    Registered User
    Join Date
    Apr 2014
    Posts
    7

    Re: GifRenderer ArgumentException: Value does not fall within the expected range

    Simple as imagined
    Unfortunately the staff of DVLUP has confirmed to me that the requirement is just to save the gif in the library, this is possible with WP8.1, I'm considering to migrate my app, but I have not much time available

    Thanks again

  13. #13
    Nokia Developer Moderator
    Join Date
    Oct 2006
    Location
    Finland
    Posts
    4,572

    Re: GifRenderer ArgumentException: Value does not fall within the expected range

    For information: This thread has been featured and you can find the details in the blog

Similar Threads

  1. Replies: 0
    Last Post: 2013-08-18, 16:21
  2. Fall Detector Demo fails w/ Nokia Qt SDK 1.0
    By kevin_s2f in forum [Archived] Qt Mobility Project
    Replies: 1
    Last Post: 2010-09-01, 23:48
  3. how to give a realistic fall when a player fall?
    By custom_made in forum Mobile Java Games
    Replies: 5
    Last Post: 2008-09-11, 18:59
  4. Carbide.vs 3.0.1 fall down on RCMake.exe
    By vipako in forum Symbian Tools & SDKs
    Replies: 4
    Last Post: 2008-02-04, 11:00
  5. N73 - PC suite fall down!
    By Boult in forum PC Suite API and PC Connectivity SDK
    Replies: 2
    Last Post: 2007-09-11, 15:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×