Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
Lluis Sanchez edited this page Jul 9, 2013 · 13 revisions

The Xwt.Drawing.Image class can be used to load, transform and render images. The Image class can represent different kinds of images:

  • Bitmaps
  • Icons (a set of images in different sizes)
  • Vector images

XWT can only load bitmaps from files, but vector images and icons can be created using the XWT API.

Loading Images

Images can be loaded using several static methods available in the Image class:

  • FromFile
  • FromStream
  • FromResource

In addition, the Xwt.Drawing.ImageBuilder class can be used to create a new bitmap or vector image using the drawing API.

Choosing the Size of an Image

Bitmap images have a fixed and unique size, but vector images and icons can have several sizes. Before rendering an image (and often when assigning an image to a widget, such as an ImageView) you have to make sure the image has a specific size. To select the size of an image, you can use the WithSize() method:

Image image = ... // Got an image
var smallImage = image.WithSize (16, 16);

You can check if the image has a size using the HasFixedSize property.

## Image Size

Image sizes are always specified and provided in logical pixels.

## Multi-resolution and multi-size images

XWT has support for multi-resolution and multi-size images. It means that a single Image object can contain several versions of the same image in different resolutions and in different sizes. When rendering the image, XWT choses the best image version, based on the resolution of the target surface and the desired size.

For example, you may have an image of logical size 16x16 with 2 resolutions: single resolution (where 1 logical pixel = 1 physical pixel) and double/retina resolution (where 1 logical pixel = 2 physical pixels). In that case, the Image object would be represented by 2 bitmaps with a size of 16x16 and 32x32 physical pixels.

On the other hand, an Image object may represent an image with two logical sizes 16x16 and 32x32. This image would internally contain two bitmaps of 16x16 and 32x32 physical pixels.

Clone this wiki locally