在 WPF 中加载并合并两个图像
我尝试编写一个应用程序,从 WPF 中加载的 jpeg 创建带水印的图像。 我想在 WPF 中加载 jpeg 图像,并使用带有透明区域的预定义 png 来绘制它。 我尝试创建两个图像作为 RenderTargetBitmap,然后创建一个新的 RenderTargetBitmap,
Image LoadSource(string file) {
var image = new Image();
var src = new BitmapImage();
src.BeginInit();
src.UriSource = new Uri(file, UriKind.Absolute);
src.CacheOption = BitmapCacheOption.OnLoad;
src.EndInit();
image.Source = src;
image.Stretch = Stretch.Uniform;
image.Width = 1024;
image.Height = 768;
return image;
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
var imgA = LoadSource(@"D:\test\1.jpg");
var imgB = LoadSource(@"D:\test\2.png");
var bmp = new RenderTargetBitmap(1024, 768, 120, 96, PixelFormats.Pbgra32);
bmp.Render(imgA);
bmp.Render(imgB);
ResultImage.Source = bmp;
}
但它不起作用。
谁能指出我的解决方案吗?
I try to write an application that create a watermarked image from the loaded jpeg in WPF.
I want to load in WPF an jpeg image and draw it with a predifined png with a transparence region over.
I've tried to create two images as the RenderTargetBitmap and then create a new RenderTargetBitmap like
Image LoadSource(string file) {
var image = new Image();
var src = new BitmapImage();
src.BeginInit();
src.UriSource = new Uri(file, UriKind.Absolute);
src.CacheOption = BitmapCacheOption.OnLoad;
src.EndInit();
image.Source = src;
image.Stretch = Stretch.Uniform;
image.Width = 1024;
image.Height = 768;
return image;
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
var imgA = LoadSource(@"D:\test\1.jpg");
var imgB = LoadSource(@"D:\test\2.png");
var bmp = new RenderTargetBitmap(1024, 768, 120, 96, PixelFormats.Pbgra32);
bmp.Render(imgA);
bmp.Render(imgB);
ResultImage.Source = bmp;
}
but it doen't work.
Can anyone point me at the solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个更简单的解决方案:
XAML:
代码隐藏:
I have an easier solution:
XAML:
Code behind: