Introduction:
There may be many cases ,in which you need to supply higher quality images that should be fit into current device screen resolutions and its makes nice attractions for app users. Fortunately windowsphone is very good at detecting screen resolutions.However previously in windowsphone 8.0,to determine screen resolutions we are using the "App.Current.Host.Content.ScaleFactor" .But now its not working in windowsphone 8.1,So this post is explained about what is the alternative way for detecting screen resolutions in windowsphone store 8.1.Building the sample:
- Make sure you’ve downloaded and installed the Windows Phone SDK. For more information, see Get the SDK.
- I assumes that you’re going to test your app on the Windows Phone emulator. If you want to test your app on a phone, you have to take some additional steps. For more info, see Register your Windows Phone device for development.
- This post assumes you’re using Microsoft Visual Studio Express 2013 for Windows.
Description:
Lets start to comparisons between wp8.0 vs wp8.1 while detecting the screen resolutions.
WindowsPhone 8.0:
in windowsphone 8,ScaleFactor is useful for determine screen resolutions.
string ScreenScaleFactor = App.Current.Host.Content.ScaleFactor.ToString();
if (App.Current.Host.Content.ScaleFactor == 100)
{
ScreenScaleFactor = "WVGA";
}
else if (App.Current.Host.Content.ScaleFactor == 160)
{
ScreenScaleFactor = "WXGA";
}
else if (App.Current.Host.Content.ScaleFactor == 150)
{
ScreenScaleFactor = "720p";
}
MessageBox.Show(ScreenScaleFactor);
WindowsPhone 8.1:In wp8.1 the following no.of screen images availableSo lets start to detect screen resolutionsStep1: Get the number of raw (physical) pixels for a current viewStep2: Get the current boundsStep3: Finally multiply bounds 'width' and 'height' values individually with raw pixelsvar scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel; string currentresolution = Window.Current.Bounds.Width * scaleFactor + "*" + Window.Current.Bounds.Height * scaleFactor; MessageDialog messageDialog = new MessageDialog(currentresolution); await messageDialog.ShowAsync();
ScreenShots:1)Emulator 8.1 WVGA 4 inch 520MB:
2)Emulator 8.1 WXGA 4 inch:Note: Please share your thoughts,what you think about this post,Is this post really helpful for you?otherwise it would be very happy ,if you have any thoughts for to implement this requirement in any another way?I always welcome if you drop comments on this post and it would be impressive.Follow me always at @Subramanyam_BHave a nice day by Subramanyam Raju :)
How to get screen resolution in Inches i.e. how much this phone size in inches? either it be 4", 4.5", 5" or 6". Please provide the code for Windows Phone 8.1.
ReplyDelete