我尝试使用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;
}
答案 0 :(得分:2)
正如评论中所讨论的,我建议采用另一种方法:使用更多的标准&#34;渲染链,而不是使用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
}
我在样本中尝试了这个解决方案,但我看不到任何文物。请回来报告你的结果!