Discussion Board

Results 1 to 13 of 13

Hybrid View

  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
    529

    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
    529

    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
    529

    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.

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
  •  
×