c# - Windows 应用商店应用程序 - WriteableBitmap ,blit 方法

标签 c# windows-store-apps blit writeablebitmapex

好吧,我正在尝试使用 writeablebitmapex 库的 blit 方法合并两个图像(将一个图像叠加在另一个图像之上)。应用 blit 后,我​​得到的只是一个没有内容的透明图像。

我想将窗帘图像叠加在 window 图像的顶部。

源代码:

WriteableBitmap photoWriteableBitMap = await new WriteableBitmap(1,1).FromContent(new Uri("ms-appx:///Curtain1.jpg"));
WriteableBitmap frameWriteableBitMap = await new WriteableBitmap(1, 1).FromContent(new Uri("ms-appx:///Window1.jpg"));

var merge = new WriteableBitmap(750, 750);

merge.Blit(new Rect(0, 0, 100, 100), photoWriteableBitMap, new Rect(0, 0, photoWriteableBitMap.PixelWidth, photoWriteableBitMap.PixelHeight));
merge.Blit(new Rect(0, 0, 200, 200), frameWriteableBitMap, new Rect(0, 0, frameWriteableBitMap.PixelWidth, frameWriteableBitMap.PixelHeight));

// Assign the merged writeable bitmap to the image source.
imgMain.Source = merge; 

预期图像:Expected image

实际图片:Actual image

请让我知道我做错了什么。

最佳答案

我已经找到了解决方案的答案,以防有人在这里偶然发现。

首先,我不必要地尝试包含额外的位图(合并)以获得所需的输出。

我所要做的就是在窗口图像上应用位图传输,并适本地设置源矩形和目标矩形。

下面是对我有用的最终代码,

WriteableBitmap photoWriteableBitMap = await new WriteableBitmap(1, 1).FromContent(new Uri("ms-appx:///Curtain1.jpg"));
WriteableBitmap frameWriteableBitMap = await new WriteableBitmap(1, 1).FromContent(new Uri("ms-appx:///Window1.jpg"));

frameWriteableBitMap.Blit(new Rect(300, 100, 250, 200), photoWriteableBitMap, new Rect(0, 0, photoWriteableBitMap.PixelWidth , photoWriteableBitMap.PixelHeight));

这就是我的最终图像的样子:enter image description here

关于c# - Windows 应用商店应用程序 - WriteableBitmap ,blit 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35309198/

相关文章:

c# - “Code First From Database”模板未显示在 Visual Studio 实体数据模型向导中

c# - 如何使用 HttpClient 将带有 JSON 的 DELETE 发送到 REST API

c# - Head First C# 练习

c# - 带有边界框缩放点框的用户控件

python - Pygame blit 区域参数?

python - 在 Pygame 中使用 screen.blit 时可以使用 .format 功能吗?

c# - CS0311 C# 该类型不能用作泛型类型或方法中的类型参数 'TContext'。 Entity Framework 核心

windows-8 - Windows RT 中的网络资源限制

c# - Lambda 表达式作为参数用作 AsTask() 回调

c - SDL - Blit Surface 将浮点值作为 rect 参数传递