Lumia Imaging SDK图像混合创建分离线



我试图使用Lumia Imaging SDK的JpegTools.BlendAsync()方法创建平铺背景。我在循环中调用该方法来合并所有平铺图像。这种方法是有效的,但是在输出图像中有不需要的线条。这些分隔线出现在单个瓦片图像的边界;合并并不干净。

我的代码是附加的。是我在逻辑上做错了什么,还是这是SDK中的错误?

bitmapSource为单个瓷砖,jpegSource为由瓷砖填充的空布局,bgSize为背景尺寸的大小。

async private static Task<IBuffer> CreateTile(IBuffer jpegSource, IReadableBitmap bitmapSource, Size tileSize, Size bgSize)
        {
            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);
            while (currentBgHeight < outBgHeight)
            {
                while (currentBgWidth < outBgWidth)
                {
                    jpegSource = await JpegTools.BlendAsync(jpegSource, bitmapSource, blendPosition);
                    blendPosition.X += tileWidth;
                    currentBgWidth += tileWidth;
                }
                blendPosition.Y += tileHeight;
                currentBgHeight += tileHeight;
                currentBgWidth = 0;
                blendPosition.X = 0;
            }
            return jpegSource;
        }

正如评论中讨论的那样,我建议使用另一种方法:通过使用更"标准"的渲染链,而不是使用JpegTools。

其中一些是基于您的代码示例,但我已经尝试使其尽可能通用。

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
}

我在一个样品中尝试了这个解决方案,我看不到任何伪影。请务必回来报告你的结果!

最新更新