One approach could be to create a
RenderBitmapTarget
and draw the source image onto that. And then use that as the source of another
Image
.
Consider this example;
<window x:class="WpfApplication9.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyAwesomeWindow" Height="350" Width="525">
<grid>
<grid.rowdefinitions>
<rowdefinition height="*" />
<rowdefinition height="*" />
<rowdefinition height="Auto" />
</grid.rowdefinitions>
<image x:name="Src" grid.row="0" source="C:\Temp\someimage.png" />
<image x:name="Dst" grid.row="1" />
<button grid.row="2" content="Do it!" click="ButtonBase_OnClick" />
</grid>
</window>
With the backing code of;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Media;
namespace WpfApplication9 {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e) {
var visual = new DrawingVisual();
var context = visual.RenderOpen();
context.DrawImage(Src.Source, new Rect(0, 0, Src.Source.Width, Src.Source.Height));
context.DrawLine(new Pen(Brushes.PeachPuff, 4.0), new Point(0, 0), new Point(100, 100));
context.Close();
var renderTarget = new RenderTargetBitmap((int)Src.Source.Width, (int)Src.Source.Height, 96, 96, PixelFormats.Pbgra32);
renderTarget.Render(visual);
Dst.Source = renderTarget;
}
}
}
In the above example the image, as rendered onto the top image,
Src
, is draw onto the
Dst
image when the button is clicked. As the
RenderContext
is available you can manipulate the image any which way you like.
Hope this helps,
Fredrik