Nevron Open Vision Documentation
Raster Images

Raster images are made up of a set grid of dots called pixels where each pixel is assigned a color value. This makes raster images resolution dependent and their quality deteriorates when they are scaled up or down.

Raster Image Formats

Image formats are represented by the NImageFormat type. The framework supports the following commonly used formats for image interchange and presentation:

NOV’s imaging library provides its own implementations of the encoders and decoders listed above, so that the functionality is available on all supported platforms. Furthermore, the library can use platform-provided image codecs where they are available.

The built-in formats can be accessed through static fields of NImageFormat – for example NImageFormat.Jpeg denotes the JPEG format, NImageFormat.Png – the PNG format, etc.

It is possible to register a custom image format using the NImageFormat.CreateFormat method. The method requires an instance of a type that implements the INImageFormatProvider interface.

Besides the common formats, the framework also offers its own image format called Nevron Raster Image (NRI). A NRI file consists of a signature, followed by a file header with basic image information and the pixel data in uncompressed form. The NRI image format is described in the table below:

Signature 3 bytes (UTF-8 encoded "NRI")
Width 4 bytes, Int32
Height 4 bytes, Int32
Resolution 4 bytes, Single
PixelFormat 1 byte
Pixel Data (Stride * Height) bytes, where Stride is the number of bytes per row, aligned to 4 bytes
Creating Raster Images

You can create images by using one of the constructors of the NImage class.

Alternatively you can use one of the following static methods of the NImage class:

You can also create raster images by passing an image source to the corresponding NImage constructor. For more information take a look at the Image Sources section at the end of this topic.

Displaying Raster Images

NImage is an attribute type that represents images within the Document Object Model. It acts as a wrapper around NImageSource that helps for the integration of image sources inside the DOM.

Each NImage object contains an NImageSource instance that is assigned at construction time. Most of the NImage constructors create this instance internally, but it is also possible to specify an existing NImageSource instance. The following example demonstrates the initialization of an NImage object with a file image source:

Creating an NImage object
Copy Code
NImage image = NImage.FromFile(@"D:\TestImage.png");

The newly created NImage object can be assigned as an attribute to a DOM node. For example, the image box widget (NImageBox) has a property of type NImage, which specifies the displayed image: 

Changing the image of an ImageBox widget
Copy Code
NImageBox imageBox = new NImageBox();
imageBox.Image = image;

You can also use an image to create an image fill, which can then be used to fill an arbitrary widget. The following example fills a stack panel with an image:

Filling a widget with an image
Copy Code
NImage image = NImage.FromFile(@"D:\flower.png");
stackPanel.BackgroundFill = new NImageFill(image);
You can use the TextureMapping property of the image box or the image fill to specify how the image should be rendered in the available area.
Image Sources

The sources of image data used in an application can vary from embedded resources and in-memory buffers to local files and web images. To ensure that all these types of sources can be used transparently with the framework graphics and the DOM, the NOV framework provides a set of types to represent images with different physical location and provide convenient access to them. The base type for all image sources is called NImageSource. The following table displays the hierarchy of image source types:

 

Type Description
NImageSource Abstract base type for all image sources.
NRasterImageSource The image source is an NRaster object.
NEncodedImageSource Abstract base type for image sources that provide encoded image data.
NBytesImageSource The image source is a byte array containing encoded image data.
NEmbeddedResourceImageSource The image source is an embedded resource containing encoded image data.
NUriImageSource Abstract base class for image sources the location of which is specified with an URI
NFileImageSource The image source is a local or network file.
NHttpImageSource The image source is a file accessible through HTTP.

Following are several examples that demonstrate how image sources are created and used. The code below paints a few rectangles in a raster object and creates an NRasterImageSource from it:

Creating a Raster Image Source
Copy Code
NRaster raster = new NRaster(100, 60, NPixelFormat.ARGB32);
raster.Clear(NColor.OliveDrab);
raster.FillRect(NColor.Crimson, new NRectangleI(10, 10, 70, 30));
raster.FillRect(NColor.Orange, new NRectangleI(20, 20, 70, 30));
NRasterImageSource rasterImgSrc = new NRasterImageSource(raster);

The generated image can be painted on the screen or in another rendering context using an NPaintVisitor object:

Drawing an image
Copy Code
visitor.PaintImage(rasterImgSrc, new NPoint(10, 10));

The result is displayed below:

Any other type of image source can be rendered the same way. For example, for an image contained in a local file the following code can be used:

Drawing an image from a File Image Source
Copy Code
  NFileImageSource fileImgSrc = new NFileImageSource(new NUri(@"D:\TestImage.png"));
  ...
  visitor.PaintImage(fileImgSrc, new NPoint(10, 10));

When dealing with remotely located resources the data does not become available instantly – there is a period of time during which the data is traveling towards the recipient. During this period the image source object can still be used, but it renders an empty image. When the actual image data arrives, the image source raises the ImageSourceChanged event. This notification can be used to initiate a repaint of the widget that displays the image source.

Some encoded image sources may contain more than one image – for example GIF files with multiple frames. Such images can be displayed either by rendering a particular frame or by playing back the whole sequence of frames as an animation. To indicate your preferences you can use the AnimateFrames and FrameIndex properties. These properties are not regarded for images that contain only one frame or do not support animation.

All types derived from NImageSource implement common functionality that facilitates the access to the image information. In general all image sources are able to:

For image sources with multiple frames it is possible to obtain the number of frames, as well as information about each particular frame. Please refer to NImageInfo.FrameCount and NImageInfo.GetFrameInfo for details.

See Also
Send Feedback