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);

The WithSize(16, 16) call returns a copy of the image that has a size fixed to 16x16. Notice that this method does not make a copy of the underlying physical image, it just creates a new Image wrapper with a fixed size, so it is a very lightweight operation.

This method can also be used to scale Bitmaps, and it is still a lightweight operation since the bitmap is not really physically scaled. WithSize simply sets the size that has been chosen for rendering.

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