Skip to content

Commit

Permalink
Fix horizontal flip of photo from remote camera.
Browse files Browse the repository at this point in the history
  • Loading branch information
andijakl committed Sep 19, 2016
1 parent 9225e5d commit f2b821c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
14 changes: 7 additions & 7 deletions KissMachineKinect/KissMachineKinect.Windows/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ private async void CoreWindow_KeyUp(CoreWindow sender, KeyEventArgs args)
break;
case VirtualKey.A:
{
#if DEBUG
//#if DEBUG
// Add new player (for debug)
var newPlayer = new PlayerInfo(_drawingCanvas, 1, -1)
{
Expand All @@ -500,7 +500,7 @@ private async void CoreWindow_KeyUp(CoreWindow sender, KeyEventArgs args)
};
newPlayer.SetVisibility(true);
_players.Add(newPlayer);
#endif
//#endif
}
break;
}
Expand Down Expand Up @@ -830,7 +830,7 @@ private async Task TakePhoto()
{
// Try to take the picture with the connected Sony camera
var photoFile = await _sonyCameraService.TakePhoto();
await LoadFileToViewfinderBitmap(photoFile, true);
await LoadFileToViewfinderBitmap(photoFile);
}
catch (Exception e)
{
Expand All @@ -842,19 +842,19 @@ private async Task TakePhoto()
}
}

private async Task LoadFileToViewfinderBitmap(StorageFile photoFileName, bool horizontallyFlipImage)
private async Task LoadFileToViewfinderBitmap(StorageFile photoFileName)
{
using (var stream = await photoFileName.OpenAsync(FileAccessMode.ReadWrite))
{
TakenPhotoBitmap = new WriteableBitmap(1, 1);
TakenPhotoBitmap.SetSource(stream);
var tmpBmp = await BitmapFactory.New(1, 1).FromStream(stream);
Debug.WriteLine("Photo size: " + tmpBmp.PixelWidth + " / " + tmpBmp.PixelHeight);
// Flip image from camea horizontally.
// Kinect shows images as flipped to match the viewfinder with a mirror.
// External camera has everything as it should be.
// -> we need to rotate external camera for display so that it corresponds
// to what people are expecting.
// Do not flip the final image, as it'd be wrong actually.
TakenPhotoBitmap.Flip(WriteableBitmapExtensions.FlipMode.Horizontal);
TakenPhotoBitmap = tmpBmp.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
TakenPhotoBitmap.Invalidate();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace KissMachineKinect.Services
{
public class SonyCameraService : INotifyPropertyChanged
{
private const ApiVersion CameraApiVersion = ApiVersion.V1_2;
public enum CameraStatusValues
{
NotConnected,
Expand Down Expand Up @@ -156,7 +157,7 @@ private async void DiscoveryOnSonyCameraDeviceDiscovered(object sender, SonyCame

private async Task<Event> GetCameraStatusAsync()
{
var camStatus = await _camera.GetEventAsync(false, ApiVersion.V1_2);
var camStatus = await _camera.GetEventAsync(false, CameraApiVersion);
Debug.WriteLine("Camera status: " + camStatus.CameraStatus);
return camStatus;
}
Expand All @@ -170,7 +171,7 @@ public async Task PrepareTakePhoto()

try
{
var camStatus = await _camera.GetEventAsync(false, ApiVersion.V1_2);
var camStatus = await _camera.GetEventAsync(false, CameraApiVersion);
Debug.WriteLine("Camera status: " + camStatus.CameraStatus);

// We need to start rec mode before taking pictures
Expand Down

0 comments on commit f2b821c

Please sign in to comment.