C# Lumia Imaging SDK图像混合创建分隔线

C# Lumia Imaging SDK图像混合创建分隔线,c#,windows-phone-8.1,lumia-imaging-sdk,C#,Windows Phone 8.1,Lumia Imaging Sdk,我正在尝试使用Lumia Imaging SDK的JpegTools.BlendAsync()方法创建平铺背景。我在循环中调用该方法来合并所有平铺图像。该方法可行,但输出图像中存在不需要的线条。这些分隔线出现在单个平铺图像的边界处;合并不干净 附上我的密码。我是否在逻辑上做了错误的事情,或者这是SDK中的错误 bitmapSource是单个磁贴,jpegSource是由磁贴填充的空布局,bgSize是背景尺寸的大小 async private static Task<IBuffer>

我正在尝试使用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;
        }
异步私有静态任务CreateTile(IBuffer jpegSource、iReadableBitMapSource、Size tileSize、Size bgSize)
{
int outBgWidth=(int)bgSize.Width;
int-outbghight=(int)bgSize.Height;
int tileWidth=(int)tileSize.Width;
int tileHeight=(int)tileSize.Height;
int currentBgWidth=0;
int currentBgHeight=0;
点混合位置=新点(0,0);
同时(当前高度<向外高度)
{
同时(currentBgWidth
如评论中所述,我建议另一种方法:使用更“标准”的渲染链,而不是使用JPEG工具

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

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
}
intoutbgwidth=(int)bgSize.Width;
int-outbghight=(int)bgSize.Height;
int tileWidth=(int)tileSize.Width;
int tileHeight=(int)tileSize.Height;
int currentBgWidth=0;
int currentBgHeight=0;
点混合位置=新点(0,0);
使用(var backgroundCanvas=new ColorImageSource(新大小(outBgWidth,outBgHeight),Color.FromArgb(255,0,0,0))//创建具有输出大小的黑色画布。
使用(var tileSource=new BitmapImageSource(bitmapSource))
使用(var renderer=newjpegrenderer(backgroundCanvas))
{
同时(当前高度<向外高度)
{
同时(currentBgWidth

我在一个示例中尝试了这个解决方案,但没有看到任何工件。请务必回来报告您的结果

你能提供结果的图像,让我们看看你看到了什么样的人工制品吗?它可能只是循环中的一个问题,或者实际上是一个更大的问题——可能是在sdk中。您也可以尝试使用Blendefect的“本地混合”功能(或BlendingFilter,具体取决于您使用的sdk版本)来获得相同的结果。查看BlendEffect.TargetArea属性来实现这一点。@DavidBožjak我得到了:通过上面给定的循环。我可以通过重叠一个像素来提高质量,得到以下结果:。第二个稍微好一点,但线条仍然可见。有趣。此时,我只能推荐使用BlendFilter/BlendEffect的本地混合来完成这项工作。JpegTools是一组未被积极关注的遗留API:我看不出您的代码中有任何错误,也没有可以尝试调整以获得不同结果的传统选项。Ok。我将把它作为一个问题的答案来写,尽管这确实是一种替代方法。基于这个答案,我在LumiaImagingSDK Extras开源项目中添加了一个新的ImageProvider“RepeatedTileImageSource”:这个解决方案可行,但我仍然得到了不需要的分隔线(这里:)。你能试试这个()看看你得到了什么吗?@Flipper很抱歉,我看不到任何分隔线:你确定你传递了正确的tileSize尺寸吗?只是为了确保你可以使用LumiaImagingSDK来获取尺寸。您可以在源代码上调用GetInfoAsync()。返回的ImageProperties将具有“ImageSize”属性。我想不出他们为什么会有不同,但也许值得一试。我仍然无法解决这个问题。我甚至在Github使用了你的库,但我仍然在Lumia和920两部手机上得到了不需要的分隔线。我们可以讨论一下吗?