Lumia Imaging SDK image blending creates separation lines

前端 未结 1 705
小蘑菇
小蘑菇 2021-01-25 10:29

I\'m trying to create a tiled background using the Lumia Imaging SDK\'s JpegTools.BlendAsync() method. I call the method in a loop to merge all the tiled images. Th

1条回答
  •  温柔的废话
    2021-01-25 11:20

    As discussed in the comments, I suggest an alternate way of doing this: By using a more "standard" rendering chain, instead of using JpegTools.

    Some of this is based on your code sample, but I've tried making it as general as possible.

    int outBgWidth = (int)bgSize.Width;
    int outBgHeight = (int)bgSize.Height;
    int tileWidth = (int)tileSize.Width;
    int tileHeight = (int)tileSize.Height;
    
    int currentBgWidth = 0;
    int currentBgHeight = 0;
    
    Point blendPosition = new Point(0, 0);
    
    using (var backgroundCanvas = new ColorImageSource(new Size(outBgWidth, outBgHeight), Color.FromArgb(255, 0, 0, 0)))  //Create a black canvas with the output size.
    using (var tileSource = new BitmapImageSource(bitmapSource))
    using (var renderer = new JpegRenderer(backgroundCanvas))
    {
        while (currentBgHeight < outBgHeight)
        {
            while (currentBgWidth < outBgWidth)
            {
                var blendEffect = new BlendEffect();
                blendEffect.BlendFunction = BlendFunction.Normal;
                blendEffect.GlobalAlpha = 1.0;
    
                blendEffect.Source = renderer.Source;
                blendEffect.ForegroundSource = tileSource;
                blendEffect.TargetArea = new Rect(blendPosition, new Size(0, 0));   //Since we are PreservingSize the size doesn't matter. Otherwise it must be in relative coordinate space!
                blendEffect.TargetOutputOption = OutputOption.PreserveSize;
    
                renderer.Source = blendEffect;
    
                currentBgWidth += tileWidth;
                blendPosition.X = (double)currentBgWidth / (double)outBgWidth;  //Careful, the target area is in relative coordinates
            }
    
            currentBgHeight += tileHeight;
            blendPosition.Y = (double)currentBgHeight / (double)outBgHeight;    //Careful, the target area is in relative coordinates
            blendPosition.X = 0.0;
            currentBgWidth = 0;
        }
    
        var result = await renderer.RenderAsync();   //An IBuffer containing the Jpeg file
    }
    

    I have tried this solution in a sample and I can't see any artifacts. Please do come back and report your results though!

    0 讨论(0)
提交回复
热议问题