Skip to Main Content
Programming WPF, 2nd Edition
book

Programming WPF, 2nd Edition

by Chris Sells, Ian Griffiths
August 2007
Intermediate to advanced content levelIntermediate to advanced
864 pages
25h 52m
English
O'Reilly Media, Inc.
Content preview from Programming WPF, 2nd Edition

Bitmaps

WPF supports bitmaps in any of the following formats:[90] BMP, JPEG, PNG, TIFF, Windows Media Photo, GIF, and ICO (Windows icon files). You can use any image format to create a brush with which to paint any shape or text, as discussed later in the "ImageBrush" section of this chapter. The System.Windows.Media.Imaging namespace provides classes that let you work with the pixels and metadata of image files. However, the simplest way to use a bitmap is with the Image element.

Image

Image simply displays an image. It derives from FrameworkElement, so you can place it anywhere in the visual tree, and it obeys the normal layout rules. You tell it what image to display by setting its Source property, as shown in Example 13-27.

Example 13-27. Image element

<Image Source="http://www.interact-sw.co.uk/images/M3/BackOfM3.jpeg" />

Setting the Source property to an absolute URL causes the image to be downloaded and displayed. Alternatively, if you embed an image file in your application as a resource, as described in Chapter 12, you can refer to it with a relative URL, as Example 13-28 illustrates.

Example 13-28. Using an image resource

<Image Source="/MyEmbeddedImage.jpeg" />

The Image element is able to resize the image. The exact behavior depends on your application's layout. If your layout permits the Image element to size to content, it will show the image at its natural size. (We discussed sizing to content in Chapter 3.) For example, the Canvas panel never imposes a particular size on ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming C#, 4th Edition

Programming C#, 4th Edition

Jesse Liberty
Programming C# 10

Programming C# 10

Ian Griffiths

Publisher Resources

ISBN: 9780596510374Supplemental ContentErrata Page