I have a Image control inside my wpf application, which has a large image inside of it, but the control itself is only 60x150, this means it only shows a certain portion of this image. What is the easiest way of saving the visible portion to a file?
Thank you for your help.
[EDIT] I ended up using code found here (which I've not been able to locate before posting here)...
Grid r = new Grid();
r.Background = new ImageBrush(image2.Source);
System.Windows.Size sz = new System.Windows.Size(image2.Source.Width, image2.Source.Height);
r.Measure(sz);
r.Arrange(new Rect(sz));
RenderTargetBitmap rtb = new RenderTargetBitmap((int)image2.Source.Width, (int)image2.Source.Height, 96d, 96d, PixelFormats.Default);
rtb.Render(r);
BmpBitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
FileStream fs = File.Open(@"C:\lol.png", FileMode.Create);
encoder.Save(fs);
fs.Close();