Skip to content

Commit

Permalink
Add correct aspect ratio to images
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickerson110 authored Jul 26, 2018
1 parent dd6c257 commit e3da7a4
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 e3da7a4

Please sign in to comment.