C# 如何组合两个图像?

C# 如何组合两个图像?,c#,.net-core,imagesharp,C#,.net Core,Imagesharp,使用ImageSharp for.Net core,如何将两个图像并排合并?e、 g.:使2 100x150px变为1 100x300px(或200x150px)您可以使用此代码将2个源图像绘制到正确尺寸的新图像上 它将获取两个源图像,将其大小调整为所需的精确尺寸,然后将每个源图像绘制到第三个图像上,以备保存 using (Image<Rgba32> img1 = Image.Load<Rgba32>("source1.png")) // load up source i

使用ImageSharp for.Net core,如何将两个图像并排合并?e、 g.:使2 100x150px变为1 100x300px(或200x150px)

您可以使用此代码将2个源图像绘制到正确尺寸的新图像上

它将获取两个源图像,将其大小调整为所需的精确尺寸,然后将每个源图像绘制到第三个图像上,以备保存

using (Image<Rgba32> img1 = Image.Load<Rgba32>("source1.png")) // load up source images
using (Image<Rgba32> img2 = Image.Load<Rgba32>("source2.png"))
using (Image<Rgba32> outputImage = new Image<Rgba32>(200, 150)) // create output image of the correct dimensions
{
    // reduce source images to correct dimensions
    // skip if already correct size
    // if you need to use source images else where use Clone and take the result instead
    img1.Mutate(o => o.Resize(new Size(100, 150))); 
    img2.Mutate(o => o.Resize(new Size(100, 150)));

    // take the 2 source images and draw them onto the image
    outputImage.Mutate(o => o
        .DrawImage(img1, new Point(0, 0), 1f) // draw the first one top left
        .DrawImage(img2, new Point(100, 0), 1f) // draw the second next to it
    );

    outputImage.Save("ouput.png");
}

从1.0 beta 6开始,应该是“outputImage.Mutate(o=>o.DrawImage(img1,新点(0,0),1f)//在左上角绘制第一个。DrawImage(img2,新点(100,0,1f)//在它旁边绘制第二个”。最后两个参数是swapped@TheColonel26感谢您的注意(api已更改),我已经更新了示例代码。我仍然遇到一个问题,尽管我不清楚。我尝试了newImage.Mutate(o=>o.DrawImage(leftImage,新点(0,0,1f));但我遇到了一个无法转换的错误“参数3:无法从'System.Drawing.Point'转换为'SixLabors.ImageSharp.PixelFormats.PixelColorBlendingMode'”API中显然有一个使用此签名的扩展方法。Point是
SixLabors.Primitives.Point
的一个实例。您似乎有一个
系统。如果是这种情况,您将不得不别名SixLabors.Primitives.Point指向其他对象,或者只使用完整的命名空间wh正在更新。
using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing.Drawing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;