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?
I have an easier solution:
XAML:
Code behind: