Failed to save LayerMask

1.Open a PSD and create a new image instance.
2.Create a new group and copy the old LayerMask the new group.
3.Put some pixels in the group
4. Save to PSD, PNG, JPG

PSD version has opening error in Photoshop. PS ask to correct and after correction, visual seems correct.
PNG version is corrupted
JPG version is missing Mask data.

There are so many bugs in this SDK. I am only trying to write simple program and already reported like 6 bugs so far not to mention I still found some that don’t really affecting me and I don’t brother to report.

Sample PSD:
MaskTest.zip (19.6 KB)

Samle Code:

/// <summary>
///  Create a new LayerGroup and 
///  clone old LayerMask to new Group
/// </summary>
class MovingGroupMaskTest
{

    public static void Run()
    {
        // The path to the documents directory.
        string dataDir = RunExamples.GetDataDir_PSD();

        // make changes in layer names and save it
        using (var input = (PsdImage)Image.Load(dataDir + "/MaskTest.psd"))
        {
            {
                var output = new PsdImage(input.Width, input.Height);
                LayerGroup group = null;
                LayerGroup groupBegin = null;

                //for ( int i= input.Layers.Length-1; i>= 0; i--)
                for ( int i= 0; i < input.Layers.Length; i++)
                {
                    var layer = input.Layers[i];
                    if (layer is LayerGroup)
                    {
                        var oldGroup = layer as LayerGroup;

                        if (group == null)
                        {
                            var insertAt = output.Layers.Length;
                            group = output.AddLayerGroup("Masked Group", insertAt, true);
                            groupBegin = output.Layers[insertAt + 1] as LayerGroup;
                        }

                        if (oldGroup.LayerMaskData != null)
                        {
                            group.AddLayerMask(oldGroup.LayerMaskData);             // just 
                            groupBegin.AddLayerMask(oldGroup.LayerMaskData);        // Doesn't work!
                        }
                    }
                    else
                    {
                        if (layer.Name == "Paper")
                        {
                            output.AddLayer(layer);
                        }
                        else
                        {
                            group.AddLayer(layer);
                        }
                    }
                }

                output.Save(dataDir + " /MaskTest_output.psd");                         // Error: has blend mode opening error in Photoshop CC 
                output.Save(dataDir + " /MaskTest_output.png", new PsdOptions());       // Error: Broken File
                output.Save(dataDir + " /MaskTest_output.jpg", new JpegOptions());      // Error: Missing Mask

                using (var drawToImage = new PsdImage(output.Width, output.Height))
                {
                    var graphics = new Graphics(drawToImage);
                    graphics.DrawImageUnscaled(output, 0, 0);
                    drawToImage.Save(dataDir + "/MaskTest_output_indirect.png", new PngOptions()); // Error: non broken but still missing Mask.
                }
            }


        }
    }
}

@fantasyz,

I have observed the issue shared by you and a ticket with ID PSDNET-594 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be resolved.