PutraKg
PutraKg

Reputation: 2246

Lumia Imaging SDK 3.0 Blending AutoEnhance Effect and other source throw InvalidArgumentException

I am trying to blend an existing image with another IImageProvider that has an Effect applied. I noticed there are are several Effects that throw InvalidArgumentException such as the Auto Enhance and Auto Levels. Many other Effects such as the Antique effect does not throw this error.

untitled-1

My code:

    . . .
SoftwareBitmapImageSource streamTextBitmapForeground = new SoftwareBitmapImageSource(normalizedTextSoftwareBitmap);

//using (SharpnessEffect sharpenText = new SharpnessEffect(streamTextBitmapForeground, SettingsPart.SharpnessLevel))
using (BlendEffect blendEffect = new BlendEffect(effectBackground, streamTextBitmapForeground, BlendFunction.Normal, 1.0f))
using (BitmapRenderer bitmapRenderer = new BitmapRenderer(blendEffect))
{

    Bitmap bitmap = await bitmapRenderer.RenderAsync();
    byte[] pixelBuffer = bitmap.Buffers[0].Buffer.ToArray();

    using (var stream = new InMemoryRandomAccessStream())
    {
        var pngEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream).AsTask().ConfigureAwait(false);

        pngEncoder.SetPixelData(BitmapPixelFormat.Bgra8,
            BitmapAlphaMode.Straight,
            (uint)bitmap.Dimensions.Width,
            (uint)bitmap.Dimensions.Height,
            displayInformation.LogicalDpi,
            displayInformation.LogicalDpi,
            pixelBuffer);

        await pngEncoder.FlushAsync().AsTask().ConfigureAwait(false);

        . . .

The error is raised at Bitmap bitmap = await bitmapRenderer.RenderAsync();

Perhaps I need to set some parameters like the imagesize or something but I can't figure out what I am missing from the error message. I've tried using several overloads but still no go. Any ideas?

Upvotes: 1

Views: 96

Answers (1)

Franklin Chen - MSFT
Franklin Chen - MSFT

Reputation: 4923

Thanks for reporting this issue.

As David Božjak mentioned, there are some known issues for GPU processing, you might try to set RenderOptions as CPU only.

using (BitmapRenderer bitmapRender = new BitmapRenderer(blendeffect))
{
          bitmapRender.RenderOptions = RenderOptions.Cpu;
          Bitmap bitmap = await bitmapRender.RenderAsync();
}

Verified on the Win10 14393 PC.

Upvotes: 1

Related Questions