Skip to content

Commit

Permalink
Adding image centering logic into the background image updater, also …
Browse files Browse the repository at this point in the history
…making phone desktop images wider so the sliding animation to all app works better.
  • Loading branch information
QuinnDamerell committed Jan 19, 2016
1 parent 2d6bc0d commit e667720
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
23 changes: 23 additions & 0 deletions BaconBackend/Managers/Background/BackgroundImageUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,12 @@ public async void OnRequestComplete(object sender, ImageManager.ImageManagerResp
targetImageSize = new Size(310, 128);
}
}
else if(type == UpdateTypes.Desktop && DeviceHelper.CurrentDevice() == DeviceTypes.Mobile)
{
// If we are desktop on mobile we want to do a bit larger than the screen res because
// there is a sliding image animation when you switch to all apps. Lets make the width 30% larger.
targetImageSize.Width *= 1.3;
}

// Resize the image to fit nicely
InMemoryRandomAccessStream image = await ResizeImage(response.ImageStream, targetImageSize);
Expand Down Expand Up @@ -678,16 +684,19 @@ private async Task<InMemoryRandomAccessStream> ResizeImage(InMemoryRandomAccessS

uint outputHeight = imageHeight;
uint outputWidth = imageWidth;
bool centerOnX = false;

if (widthRatio < heightRatio)
{
outputHeight = (uint)(imageHeight / widthRatio);
outputWidth = (uint)requiredSize.Width;
centerOnX = false;
}
else
{
outputWidth = (uint)(imageWidth / heightRatio);
outputHeight = (uint)requiredSize.Height;
centerOnX = true;
}

// Make an output stream and an encoder
Expand All @@ -700,6 +709,20 @@ private async Task<InMemoryRandomAccessStream> ResizeImage(InMemoryRandomAccessS
BitmapBounds bound = new BitmapBounds();
bound.Height = (uint)requiredSize.Height;
bound.Width = (uint)requiredSize.Width;

// Choose Fant for quality over perf.
enc.BitmapTransform.InterpolationMode = BitmapInterpolationMode.Fant;

if(centerOnX)
{
int width = ((int)outputWidth / 2) - ((int)bound.Width / 2);
bound.X = (uint)(width > 0 ? width : 0);
}
else
{
int height = ((int)outputHeight / 2) - ((int)bound.Height / 2);
bound.Y = (uint)(height > 0 ? height : 0);
}
enc.BitmapTransform.Bounds = bound;

// Do it
Expand Down
9 changes: 0 additions & 9 deletions Baconit/ContentPanels/Panels/BasicImageContentPanel.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
using BaconBackend.Managers;
using Baconit.Interfaces;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.Display;
using Windows.Storage.Streams;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;

namespace Baconit.ContentPanels.Panels
{
Expand Down

0 comments on commit e667720

Please sign in to comment.