如何将一个图像叠加到另一个图像上? [英] How can I overlay one image onto another?

查看:171
本文介绍了如何将一个图像叠加到另一个图像上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示由两个图片组成的图片。

I would like to display an image composed of two images.

我想要图片 rectangle.png 顶部上显示图片 sticker.png ,其左侧角位于像素10,10处。

I want image rectangle.png to show with image sticker.png on top of it with its left-hand corner at pixel 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;


推荐答案

您需要一个Panel才能将两个Image控件添加到。网格或画布将允许这样,但我会使用网格,因为它将约束图像控件(从而适当地拉伸或缩小它们)。

You need a Panel to add both Image controls to. A Grid or Canvas will allow this, but I would go with the Grid as it will constrain the Image controls (thereby stretching or shrinking them as appropriate).

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;

这篇关于如何将一个图像叠加到另一个图像上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆