Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将一个图像叠加到另一个图像上?_C#_Wpf_Image_Image Processing_Overlay - Fatal编程技术网

C# 如何将一个图像叠加到另一个图像上?

C# 如何将一个图像叠加到另一个图像上?,c#,wpf,image,image-processing,overlay,C#,Wpf,Image,Image Processing,Overlay,我想显示由两张图像组成的图像 我想让imagerectangle.png在其顶部显示imagesticker.png,其左侧的角位于像素10,10 这是我得到的最新信息,但是如何组合图像? Image image = new Image(); image.Source = new BitmapImage(new Uri(@"c:\test\rectangle.png")); image.Stretch = Stretch.None; image.HorizontalAlignment = Hor

我想显示由两张图像组成的图像

我想让imagerectangle.png在其顶部显示imagesticker.png,其左侧的角位于像素10,10

这是我得到的最新信息,但是如何组合图像?

Image image = new Image();
image.Source = new BitmapImage(new Uri(@"c:\test\rectangle.png"));
image.Stretch = Stretch.None;
image.HorizontalAlignment = HorizontalAlignment.Left;

Image imageSticker = new Image();
imageSticker.Source = new BitmapImage(new Uri(@"c:\test\sticker.png"));

image.OverlayImage(imageSticker, 10, 10); //how to do this?

TheContent.Content = image;

您可以将一个图像控件置于视图中另一个图像控件的顶部。将这两个图像都放置在网格或画布中,只需将其中一个图像覆盖在另一个图像上即可。这还允许您使用不透明度进行混合,效果非常好

如果您需要将它们放在同一个图像中,有几个选项

您可以对第一幅图像进行绘制,然后在第一幅图像的顶部手动“绘制”其他图像像素。然后,它可以作为显示器中图像的图像源


或者,您可以执行我上面提到的覆盖,并将其渲染为一个图形。然后可以将其用作图像源。

您需要一个面板将两个图像控件添加到其中。网格或画布将允许这样做,但我将使用网格,因为它将约束图像控件(从而适当地拉伸或收缩它们)


很好,这就是我使用的方法,只需要添加一个imageSticker.VerticalAlignment=VerticalAlignment.Top;这不是真正的叠加。如果我想在按钮上使用组合图像呢?这行不通,为什么不行?按钮可以将该网格作为其内容。
Image image = new Image();
image.Source = new BitmapImage(new Uri(@"c:\test\rectangle.png"));
image.Stretch = Stretch.None;
image.HorizontalAlignment = HorizontalAlignment.Left;

Image imageSticker = new Image();
imageSticker.Source = new BitmapImage(new Uri(@"c:\test\sticker.png"));
imageStiker.Margin = new Thickness(10, 10, 0, 0);

Grid grid = new Grid();
grid.Children.Add(image);
grid.Children.Add(imageSticker);

TheContent.Content = grid;