Skip to content

Commit

Permalink
Update CameraControl.cs
Browse files Browse the repository at this point in the history
Update the dpi parms to new WriteableBitMap
  • Loading branch information
victor-david committed Aug 21, 2020
1 parent 355d25e commit bda9d00
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Camera.App/Core/CameraControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,10 +1162,10 @@ private void InitializeWritableBitmap(DecodedVideoFrameParameters parms)
PixelFormat pixelFormat = PixelFormats.Pbgra32;
transformParameters = new TransformParameters(new System.Drawing.Size(parms.Width, parms.Height), pixelFormat);

// TODO ScreenInfo.DpiX, ScreenInfo.DpiY
Tuple<double, double> dpi = GetDpi();
writeable = new WriteableBitmap
(
parms.Width, parms.Height, 96.0, 96.0, pixelFormat, null
parms.Width, parms.Height, dpi.Item1, dpi.Item2, pixelFormat, null
);

RenderOptions.SetBitmapScalingMode(writeable, BitmapScalingMode.NearestNeighbor);
Expand All @@ -1174,6 +1174,21 @@ private void InitializeWritableBitmap(DecodedVideoFrameParameters parms)
ImageSource = writeable;
}

/// <summary>
/// Gets the DPI.
/// </summary>
/// <returns>A Tuple. Item1 is X Dpi, Item2 is Y Dpi</returns>
private Tuple<double, double> GetDpi()
{
var source = PresentationSource.FromVisual(this);
if (source != null)
{
Matrix matrix = source.CompositionTarget.TransformToDevice;
return new Tuple<double, double>(matrix.M11 * 96.0, matrix.M22 * 96.0);
}
return new Tuple<double, double>(96.0, 96.0);
}

private void RunMotionCommand(object parm)
{
if (parm is CameraMotion motion)
Expand Down

0 comments on commit bda9d00

Please sign in to comment.