Lumia Imaging SDK图像融合创建分隔线 [英] Lumia Imaging SDK image blending creates separation lines

查看:103
本文介绍了Lumia Imaging SDK图像融合创建分隔线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Lumia Imaging SDK的JpegTools.BlendAsync()方法创建平铺背景.我在循环中调用该方法以合并所有平铺的图像.该方法有效,但是输出图像中有多余的线条.这些分隔线出现在单个图块图像的边界处.合并不干净.

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. The approach works but the there are unwanted lines in the output image. These separation lines appear at the boundaries of the single tile image; the merging is not clean.

我的代码已附上.我在逻辑上做错了吗,或者这是SDK中的错误?

My code is attached. Am I doing something wrong logically or this is a bug in the SDK?

bitmapSource是单个图块,jpegSource是由图块填充的空布局,而bgSize是背景尺寸的大小.

bitmapSource is the single tile, jpegSource is the empty layout which is populated by the tile, and bgSize is the size of the dimensions of the background.

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.

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!

这篇关于Lumia Imaging SDK图像融合创建分隔线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆