How to detect screen resolution from a Direct3D app for Windows Phone 8

Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1 only

This topic shows you how to determine the screen resolution from a Windows Phone Direct3D app. Windows Phone 8 supports phones that have WVGA, WXGA, and 720p resolutions. The Bounds property of the CoreWindow class returns the screen resolution in device-independent pixels. For example, Bounds returns 480 × 800 on a WXGA phone, but the resolution of the phone in physical pixels is 768 × 1280. You can use the ResolutionScale property to determine the resolution in physical pixels from the resolution in device-independent pixels.

The following table describes the resolutions and aspect ratios you can target in your Windows Phone 8 app.

Resolution

Pixels

Aspect ratio

Change from Windows Phone OS 7.1

Scaled resolution

WVGA

480 × 800

15:9

None

480 × 800

WXGA

768 × 1280

15:9

1.6x scale

480 × 800

720p

720 × 1280

16:9

1.5x scale, 80 pixels taller (53 pixels, before scaling)

480 × 853

Deciding which images to load based on screen resolution

  • Query the ResolutionScale property. If the returned value is Scale100Percent, you know the screen is WVGA. If the returned value is Scale150Percent, the screen is WXGA. If the value is Scale16Percent, the screen is 720p.

    
    	switch (DisplayProperties::ResolutionScale) {
    
    		case ResolutionScale::Scale100Percent: LoadSmallBitmaps(); break;
    		case ResolutionScale::Scale150Percent: LoadMediumBitmaps(); break;
    		case ResolutionScale::Scale160Percent: LoadLargeBitmaps(); break;
    	}
    
    
    

Converting screen size to physical pixels

  • Call the GetForCurrentThread() method to obtain a reference to your app’s CoreWindow object. Check the Bounds property. Multiply the returned width and height by ResolutionScale / 100.0 to get the dimensions in physical pixels.

    
    	CoreWindow^ m_window = CoreWindow::GetForCurrentThread();
    	Rect bounds = m_window->Bounds;
    	bounds.Height *= ((int) DisplayProperties::ResolutionScale) / 100.0;
    	bounds.Width *= ((int) DisplayProperties::ResolutionScale) / 100.0;
    
    
    

Show:
© 2014 Microsoft