Skip to content

Commit

Permalink
Fixed save image misalignment
Browse files Browse the repository at this point in the history
  • Loading branch information
NotImplementedLife committed Jan 15, 2022
1 parent 8910e94 commit 5a67771
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions DualShot/Controls/FrameViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace DualShot.Controls
public class FrameViewer : Canvas
{
public FrameViewer()
{
{
SetLeft(FrameImage, 0);
SetTop(FrameImage, 0);
Children.Add(FrameImage);
Expand Down Expand Up @@ -53,7 +53,7 @@ public BitmapImage Frame
private static void FramePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var o = d as FrameViewer;
var i = e.NewValue as BitmapSource;
var i = e.NewValue as BitmapSource;
o.FrameImage.Source = i;
o.Width = o.FrameImage.Width = i.PixelWidth;
o.Height = o.FrameImage.Height = i.PixelHeight;
Expand Down Expand Up @@ -115,7 +115,14 @@ private static void ScreenshotPropertyChanged(DependencyObject d, DependencyProp
public void Save(string filename)
{
RenderTargetBitmap result = new RenderTargetBitmap((int)Width, (int)Height, 96, 96, PixelFormats.Pbgra32);
result.Render(this);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext ctx = dv.RenderOpen())
{
VisualBrush vb = new VisualBrush(this);
ctx.DrawRectangle(vb, null, new Rect(new Point(), new Size((int)Width,(int)Height)));
}
result.Render(dv);

var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(result));
using (var file = File.Create(filename))
Expand Down

0 comments on commit 5a67771

Please sign in to comment.