Skip to content

Commit

Permalink
Merge pull request #1 from mdickerson110/Adjust-Test-Viewer-Aspect-Ratio
Browse files Browse the repository at this point in the history
Add correct aspect ratio to images
  • Loading branch information
mdickerson110 authored Jul 26, 2018
2 parents dd6c257 + e3da7a4 commit a96d280
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions TestViewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ private void DrawImages (uint frame)

uint[] color_map = m_source.GetColorMap();

ImageXY.Source = GenerateBitmap(imageXY, color_map);
ImageXZ.Source = GenerateBitmap(imageXZ, color_map);
ImageYZ.Source = GenerateBitmap(imageYZ, color_map);
ImageXY.Source = scaleBitmap(GenerateBitmap(imageXY, color_map), bboxXY.dir1_x, bboxXY.dir2_y);
ImageXZ.Source = scaleBitmap(GenerateBitmap(imageXZ, color_map), bboxXZ.dir1_x, bboxXZ.dir2_z);
ImageYZ.Source = scaleBitmap(GenerateBitmap(imageYZ, color_map), bboxYZ.dir1_y, bboxYZ.dir2_z);
}

private WriteableBitmap GenerateBitmap(Image3d image, uint[] color_map)
Expand Down Expand Up @@ -178,6 +178,21 @@ unsafe static void SetRGBVal(byte* pixel, uint rgba)
// discard alpha channel
}

//Convert to TransformedBitmap to incorporate correct aspect ratio.
private TransformedBitmap scaleBitmap(WriteableBitmap bitmap, double width, double height)
{
double widthFactor = 1;
double heightFactor = 1;

if (width > height)
widthFactor = width / height;
else
heightFactor = height / width;

return new TransformedBitmap(bitmap, new ScaleTransform(widthFactor, heightFactor));
}


static void SwapVals(ref float v1, ref float v2)
{
float tmp = v1;
Expand Down

0 comments on commit a96d280

Please sign in to comment.