📜 ⬆️ ⬇️

Create an application for Windows Phone 7 from start to finish. Part 7, the anniversary. Adding images and icons

Previous part

If you want to make your application different from the rest, you should add your own images and icons.

In this part you will learn:

Image and Icon Design Tips


You can find free artwork on the Internet or you can have artwork created by the designer. Below are some tips on how to design images and icons to match them with the same Metro design style.
Performance Improvement Tip:
Usually a JPG encoder (encoder) is much faster than a PNG encoder (encoder). If you do not need transparency, choose the JPG file format, not the PNG format. Also, try to limit the size of the images.
')

Add image to page


To display images on the page, you can specify an image in your project or bind to an image at runtime.

To add an image to the page:
  1. Add a JPG or PNG image to the project and set the Build Action to Content .
  2. Add an Image control to the page.
  3. Set the Source property of the Image control to the location of the image file.
The following XAML snippet shows how to display an image named myPicture.jpg in the Images folder in Solution Explorer (Solution Explorer).
< Image Source ="/Images/myPicture.jpg" > * This source code was highlighted with Source Code Highlighter .
  1. < Image Source ="/Images/myPicture.jpg" > * This source code was highlighted with Source Code Highlighter .
< Image Source ="/Images/myPicture.jpg" > * This source code was highlighted with Source Code Highlighter .

You can also display images by accessing them at run time. The following fragment of the XAML code of the Fuel Tracker application shows how to set the Source property to the value of the Picture property of the Car object using the markup capabilities.
  1. < Image Height = "75" Width = "75" Margin = "15" Stretch = "UniformToFill"
  2. Source = "{Binding Picture}" VerticalAlignment = "Top" />
* This source code was highlighted with Source Code Highlighter .

image

Adding a background image to the page


Sometimes you might want to display an image behind controls and other user interface elements on the page. The first step in adding a background image to a page is selecting the image to display. Some recommendations when choosing a background image:
Interface Design Recommendation:
Avoid using too much white in applications, for example, white background, as this can have a serious impact on the battery life of devices with an OLED display.

You may need some trial and error to select an appropriate background that appears equally well with both light and dark themes. Be sure to check the background on both topics. Below is the background image of the page used in the Fuel Tracker application, it has a transparent background.

image

The following image shows how the background image on the page looks on dark and light themes. Since it has a transparent background, the text is visible on both topics.

image

To add a background image to the page:
  1. Add images to the project and set the Build Action to Content .
  2. Create an ImageBrush resource and set the ImageSource property to the relative URI (uniform resource identifier) ​​of the image. You must also set a Key for the image.
    If you use a PNG file, you can also set the Opacity property between 0 and 1 and the Stretch property (stretching) to specify how you want to resize the image to fit the space allotted to it.
    For the Fuel Tracker application, ImageBrush is advertised in App.xaml, as this brush is used for all pages.
    1. < ImageBrush x: Key = "gasBrush" ImageSource = "/ Images / gasPump.png" Opacity = ". 1" Stretch = "UniformToFill" />
    * This source code was highlighted with Source Code Highlighter .
  3. Apply ImageBrush as the Background property for the root element or other page elements using the key set for the brush, as shown in the following XAML code fragment.
    1. <! - LayoutRoot is the root grid where all page content is placed ->
    2. < Grid x: Name = "LayoutRoot" Background = "{StaticResource gasBrush}" >
    * This source code was highlighted with Source Code Highlighter .
    You can also apply an ImageBrush using the Properties window, as shown in the following image.

    image

Adding an image to Splash Screen


When you create a new Windows Phone project in Visual Studio, you automatically get a standard splash screen called SplashScreenImage.jpg, which looks like this.

image

To add your own image to the splash screen, replace SplashScreenImage.jpg with your 480-by-800-pixel JPG file. Using a screenshot of your application is the fastest way to create a similar image.

Certification Requirement:
Your application should render the first screen within 5 seconds after launch. Using splash screen will help you fulfill this requirement.

If you want to display a more complex splash screen, such as an animation, you will not be able to use a JPG image. Keep in mind that if you use a page to display a splash screen, then this page will be part of the stack for the back button. This means that if the user presses the “Back” button on the first page of the application, a splash screen will appear instead of the expected exit from the application. To work around this problem, use Popup to create a splash screen.

Certification Requirement:
When you press the "Back" button on the first page of the application, the application should exit.

Adding an application icon


The application icon is the image that is displayed for your application in the list of phone applications. Application icons must meet the following requirements:
Below is the application icon for the Fuel Tracker.

image

Below is shown how the application icon in the list of applications.

image

To set the application icon:
  1. Add an icon to the project and set the Build Action to Content .
  2. In the project designer (Project designer), on the Application tab, specify your application icon in the Icon drop-down list.

    image

    In addition, you can change the IconPath element in the WMAppManifest.xml file to select an application icon, as shown in the following markup fragment.
    1. < IconPath IsRelative = "true" IsResource = "false" > gasIcon.png </ IconPath >
    * This source code was highlighted with Source Code Highlighter .

Adding an app tile icon


An app tile is a view of your app that appears when users place your app on the start screen.

The tile icon of the application must meet the following requirements:
Below is the tile icon for the Fuel Tracker application.

image

The following shows how the tile icon of the application looks like when the main color is green.

image

To set the tile icon of the application:
  1. Add an icon to the project and set the Build Action to Content .
  2. In the project designer (Project designer), on the Application tab, specify your tile icon in the Background image drop-down list.

    image

    In addition, you can change the BackgroundImageURI element in the WMAppManifest.xml file to select an application icon, as shown in the following markup fragment.
    1. < PrimaryToken TokenID = "FuelTrackerToken" TaskName = "_ default" >
    2. < TemplateType5 >
    3. < BackgroundImageURI IsRelative = "true"
    4. IsResource = "false" > gasTileIcon.png </ BackgroundImageURI >
    5. < Count > 0 </ Count >
    6. < Title > Fuel Tracker </ Title >
    7. </ TemplateType5 >
    8. </ PrimaryToken >
    * This source code was highlighted with Source Code Highlighter .
Next part

Source: https://habr.com/ru/post/118242/


All Articles