microsoft / Lumia-imaging-sdk

Lumia Imaging SDK is a comprehensive set of GPU/CPU imaging tools and effects that run on both mobile and desktop, with high speed and memory efficiency. Samples and extras code are included.
MIT License
75 stars 37 forks source link

Rendering Effectlist always gives InvalidcastException #16

Closed SeriousGeorge closed 8 years ago

SeriousGeorge commented 8 years ago

I try to render multiple effects as a list (the amount and order of the effects can be dynamic). But everytime I render more than the Source it throws an InvalidCastException.

Working code with source only: ` applicationData = ApplicationData.Current; localFolder = applicationData.LocalFolder; imageFile = await localFolder.GetFileAsync("pic.jpg"); IAsyncOperation stream = FileIO.ReadBufferAsync(imageFile);

        var scale = new ScaleEffect(2);
        var rotation = new RotationEffect(30);
        var blur = new BlurEffect(10);

        using (var source = new BufferProviderImageSource(stream.AsBufferProvider()))
        {
            EffectList list = new EffectList() {Source = source};
            using (WriteableBitmapRenderer renderer = new WriteableBitmapRenderer(list))
            {
                renderer.OutputOption = OutputOption.PreserveAspectRatio;
                renderer.WriteableBitmap = new WriteableBitmap(1024,768);

                WriteableBitmap wp = await renderer.RenderAsync();
                imageControl.Source = wp;
            }
        }

`

Not working with list: ` applicationData = ApplicationData.Current; localFolder = applicationData.LocalFolder; imageFile = await localFolder.GetFileAsync("pic.jpg"); IAsyncOperation stream = FileIO.ReadBufferAsync(imageFile);

        var scale = new ScaleEffect(2);
        var rotation = new RotationEffect(30);
        var blur = new BlurEffect(10);

        using (var source = new BufferProviderImageSource(stream.AsBufferProvider()))
        {
            EffectList list = new EffectList() {source,scale,rotation,blur};
            using (WriteableBitmapRenderer renderer = new WriteableBitmapRenderer(list))
            {
                renderer.OutputOption = OutputOption.PreserveAspectRatio;
                renderer.WriteableBitmap = new WriteableBitmap(1024,768);

                WriteableBitmap wp = await renderer.RenderAsync();
                imageControl.Source = wp;
            }
        }

`

I also tried with JpegRenderer... same result. Additionally I can't find any complete sample using EffectList().

davidbozjak commented 8 years ago

In your second code sample you are not actually setting a source. You are just sending in a list of four items. Try something like this:

EffectList list = new EffectList() {scale,rotation,blur}; list.Source = source;

See more at: https://msdn.microsoft.com/en-us/library/lumia.imaging.effectlist_members.aspx

SeriousGeorge commented 8 years ago

Wow, that was quick. Thanks a lot! It's working now.