×

Image sources

A source image may exist in various formats and containers. The developer has the choice to use either compressed data, such as JPEG (small memory footprint), or to work with raw bitmaps, whichever suits her needs better. This topic describes the image source classes available in the Nokia Imaging SDK.

BitmapImageSource

Used when the source image is raw pixels in a Nokia.Graphics.Imaging.Bitmap. Also, a WriteableBitmap can be used via the provided extension method AsBitmap:

using Nokia.InteropServices.WindowsRuntime;
WriteableBitmap wb = new WriteableBitmap(…);
…
BitmapImageSource source = new BitmapImageSource(wb.AsBitmap());

BufferImageSource

Used when the source image is file data (JPEG/JFIF with EXIF metadata, PNG, and so on) in a WinRT IBuffer.

CameraPreviewImageSource (Windows Phone)

Used when the source image is the preview buffer of an ICameraCaptureDevice. Every time RenderAsync is called on the processing pipeline, this image source will load the most recent preview image that is available. Other than reading preview dimensions and pixel data, it does not affect the ICameraCaptureDevice, so it can be used in a drop-in manner in most capturing scenarios.

CameraPreviewImageSource (Windows)

Used when the source image is the preview of the camera stream. Since ICameraCaptureDevice is not supported by Windows, the CameraPreviewImageSouce supports the preview functionality by implementing InitializeAsync, StartPreviewAsync and StopPreviewAsync. The event PreviewFrameAvailable is raised every time a new preview frame is available. When RenderAsync is called on the processing pipeline, this image source will load the most recent preview image that is available. To be able to capture an image using the MediaCapture class, the CameraPreviewImage has to be stopped.

Note: When app is suspended, the CameraPreviewImageSource must be stopped by calling StopPreviewAsync. When the app is resumed, the CameraPreviewImageSource must be restarted by calling InitializeAsync followed by StartPreviewAsync.

ColorImageSource

Used when the source image is a constant flat colour. Using ColorImageSource makes it possible to avoid having an intermediate bitmap that consumes memory.

DelegatingImageSource

Used when the source image is to be generated by a user-implemented class that implements the ICustomImageSource interface. The user class is attached to the DelegatingImageSource upon creation. In C#, this is much simpler through the use of the CustomImageSourceBase base class. See Custom Sources and Effects.

GradientImageSource

Used when the source image is a colour gradient. Using GradientImageSource makes it possible to avoid having an intermediate bitmap that consumes memory.

The following example demonstrates how to create an image with a radial gradient that progresses from red to green:

var rad = new RadialGradient(new Windows.Foundation.Point(0.5, 0.5), new EllipseRadius(0.3, 0.3));  
rad.Stops = new GradientStop[]  {
     new GradientStop() { Color = Windows.UI.Color.FromArgb(255, 255, 0, 0), Offset = 0 },
     new GradientStop() { Color = Windows.UI.Color.FromArgb(255, 0, 255, 0), Offset = 1 }  
}; 
 
using (var grad = new GradientImageSource(new Windows.Foundation.Size(Width, Height), rad))  
{
     var buffer = await new JpegRenderer(grad).RenderAsync();  
}

Figure 1. Result of the GradientImageSource code example

RandomAccessStreamImageSource

Used when the source image is file data (JPEG/JFIF with EXIF metadata, PNG, and so on) in a WinRT IRandomAccessStream.

StorageFileImageSource

Used when the source image is file data (JPEG/JFIF with EXIF metadata, PNG, and so on) in a WinRT IStorageFile.

StreamImageSource

Used when the source image is file data (JPEG/JFIF with EXIF metadata, PNG, and so on) in a .NET System.IO.Stream.


Last updated 9 June 2014

Back to top

×