Skip to content

NativeImageRasterSource

Namespace: ThinkGeo.Core

This class allows you to view standard .NET GDI+ image types such as BMP, TIF, JPG, and PNG.

public class NativeImageRasterSource : RasterSource

Inheritance ObjectRasterSourceNativeImageRasterSource

Remarks:

This class handles all default supported image types of GDI+. As none of these types embed geographic information in them, you will need to ensure that the image file is always accompanied by a world file. The world file is text file that stores the associated geographic information we need to properly display the image along with your other feature data.

Properties

IsNegative

This property gets and sets whether the image shows as negative (inverted colors).

public bool IsNegative { get; set; }

Property Value

Boolean

Remarks:

You can set this property to show the negative of the image.

IsGrayscale

This property gets and sets whether the image shows in grayscale.

public bool IsGrayscale { get; set; }

Property Value

Boolean

Remarks:

This property allows you to show the image in grayscale.

FileName

This property returns the filename part of the PathFilename.

public string FileName { get; }

Property Value

String

Remarks:

None

FilePath

This property returns the path part of the PathFilename.

public string FilePath { get; }

Property Value

String

Remarks:

None

ImagePathFilename

This property returns the path and filename of the image you want to represent.

public string ImagePathFilename { get; set; }

Property Value

String

Exceptions

ArgumentException
Setting an invalid FilePathName structure will throw an ArgumentException.

Remarks:

When you specify the path and filename, it should be in the correct format as such; however, the file does not need to actually exist on the file system. This is to allow us to accept streams supplied by the developer at runtime. If you choose to provide a file that exists, we will attempt to use it. If we cannot find it, then we will raise the SteamLoading event and allow you to supply the stream. For example, you can pass in "C:\NotARealPath\File1.jpg" which does not exist on the file system. When we raise the event for you to supply a stream, we will pass to you the path and filename so you can differentiate the files.

ProjectionConverter

public ProjectionConverter ProjectionConverter { get; set; }

Property Value

ProjectionConverter

Projection

public Projection Projection { get; protected set; }

Property Value

Projection

Transparency

This property gets and sets the amount of transparency to apply to the image.

public float Transparency { get; set; }

Property Value

Single
This property gets the amount of transparency to apply to the image.

Remarks:

None

BlueTranslation

This property gets and sets the amount of blue to apply to the image.

public float BlueTranslation { get; set; }

Property Value

Single
This property gets the amount of blue to apply to the image.

Remarks:

None

RedTranslation

This property gets and sets the amount of red to apply to the image.

public float RedTranslation { get; set; }

Property Value

Single
This property gets the amount of red to apply to the image.

Remarks:

None

GreenTranslation

This property gets and sets the amount of green to apply to the image.

public float GreenTranslation { get; set; }

Property Value

Single
This property gets the amount of green to apply to the image.

Remarks:

None

ScaleFactor

The scale factor when drawing the primitive image. For example I am looking for an image with 100100px, If the ScaleFactor is set to 2, it means the component will get the image with 200200px. We want to keep it as 1 (by default) for most cases.

public double ScaleFactor { get; set; }

Property Value

Double

IsOpen

This property returns true if the RasterSource is open and false if it is not.

public bool IsOpen { get; protected set; }

Property Value

Boolean

Remarks:

Various methods on the RasterSource require that it be in an open state. If one of those methods is called when the state is not open, the method will throw an exception. To enter the open state, you must call the RasterSource's Open method. The method will raise an exception if the current RasterSource is already open.

Constructors

NativeImageRasterSource()

This is the constructor the for the class.

public NativeImageRasterSource()

Remarks:

None

NativeImageRasterSource(String)

This is the constructor the for the class.

public NativeImageRasterSource(string imagePathFilename)

Parameters

imagePathFilename String
This parameter represents the image you want to load.

Remarks:

You can specify a path and filename that does not actually exist if you use the StreamLoading event. This event only uses the PathFilename parameter as a unique string that will be passed to you in the event, so that you can determine what stream you want to pass back.

NativeImageRasterSource(String, String)

This is the constructor the for the class.

public NativeImageRasterSource(string imagePathFilename, string worldfilePathFilename)

Parameters

imagePathFilename String
This parameter represents the image you want to load.

worldfilePathFilename String
This parameter represents the world file path and filename you want to load.

Remarks:

You can specify a path and filename that does not actually exist if you use the StreamLoading event. This event only uses the PathFilename parameter as a unique string that will be passed to you in the event, so that you can determine what stream you want to pass back.

NativeImageRasterSource(String, RectangleShape)

This is the constructor the for the class.

public NativeImageRasterSource(string imagePathFilename, RectangleShape imageExtent)

Parameters

imagePathFilename String
This parameter represents the image you want to load.

imageExtent RectangleShape
This parameter represents the extnet of the image you want to load.

Remarks:

You can specify a path and filename that does not actually exist if you use the StreamLoading event. This event only uses the PathFilename parameter as a unique string that will be passed to you in the event, so that you can determine what stream you want to pass back.

Methods

OnStreamLoading(StreamLoadingEventArgs)

This method allows you to raise the StreamLoading event.

protected void OnStreamLoading(StreamLoadingEventArgs e)

Parameters

e StreamLoadingEventArgs

        This parameter represents the event arguments you want to raise the StreamLoading
        event with.

Remarks:

This method allows you to raise the StreamLoading event. Normally events are not accessible to derived classes, so we exposed a way to raise the event as necessary through this protected method.

GetImageWidthCore()

This method returns the width of the image in screen coordinates.

protected int GetImageWidthCore()

Returns

Int32
This method returns the width of the image in screen coordinates.

Exceptions

InvalidOperationException
In the event you attempt to call this method on a image source which has not been opened, it will throw an InvalidOperationException.

Remarks:

This method returns the width of the image in screen coordinates.

GetImageHeightCore()

This method returns the height of the image in screen coordinates.

protected int GetImageHeightCore()

Returns

Int32
This method returns the height of the image in screen coordinates.

Exceptions

InvalidOperationException
In the event you attempt to call this method on a image source which has not been opened, it will throw an InvalidOperationException.

Remarks:

This method returns the height of the image in screen coordinates.

OpenCore()

This method opens the Image so that it is initialized and ready to use.

protected void OpenCore()

Exceptions

InvalidOperationException
In the event you attempt to call this method on a image source which has already been opened, it will throw an InvalidOperationException.

NotSupportedException
If the file format you passed is not one of these: .bmp, .gif, .exig, .jpg, .png, or .tiff, we will throw a NotSupportedException.

FileNotFoundException
If the world file cannot be found using the filename you passed, we will throw an FileNotFoundException when the source is not from a stream.

Remarks:

This protected virtual method is called from the concrete public method Open. The Open method plays an important role, as it is responsible for initializing the Image. Most methods on the Image will throw an exception if the state of the Image is not opened. When the map draws each layer, it will open the Image as one of its first steps; then, after it is finished drawing with that layer, it will close it. In this way, we are sure to release all resources used by the Image.

When implementing this abstract method, consider opening files for file-based sources, connecting to databases in the database-based sources and so on. You will get a chance to close these in the Close method of the Image.

CloseCore()

This method opens the Image so that it is initialized and ready to use.

protected void CloseCore()

Remarks:

This protected virtual method is called from the concrete public method Close. The Close method plays an important role in the life cycle of the Image. It may be called after drawing to release any memory and other resources that were allocated since the Open method was called.

If you override this method, it is recommended that that you take the following things into account: This method may be called multiple times, so we suggest you write the method so that that a call to a closed FeatureSource is ignored and does not generate an error. We also suggest that in the Close you free all resources that have been opened. Remember that the object will not be destroyed, but will be re-opened possibly in the near future.

GetImageCore(RectangleShape, Int32, Int32)

This method returns an image based on the worldExtent, image width and image height.

protected GeoImage GetImageCore(RectangleShape worldExtent, int canvasWidth, int canvasHeight)

Parameters

worldExtent RectangleShape
This parameter represents the worldExtent you want to draw.

canvasWidth Int32
This parameter represents the width of the image you want to draw.

canvasHeight Int32
This parameter represents the height of the image you want to draw.

Returns

GeoImage

        This method returns an image based on the worldExtent, image width and
        image height.

Exceptions

ArgumentNullException
If you pass in a worldExtent that is invalid, we will throw an ArgumentNullException.

ArgumentException
If you pass in a worldExtent that is invalid, we will throw an ArgumentException.

ArgumentOutOfRangeException
If you pass in a image width that is smaller than or equal to 0, we will throw an ArgumentOutOfRangeException.

ArgumentOutOfRangeException
If you pass in a image height that is smaller than or equal to 0, we will throw an ArgumentOutOfRangeException.

InvalidOperationException
In the event you attempt to call this method on a image source which has not been opened, it will throw an InvalidOperationException.

Remarks:

This method is responsible for returning the image based on the parameters passed in.

GetBoundingBoxCore()

This method returns the bounding box of the RasterSource.

protected RectangleShape GetBoundingBoxCore()

Returns

RectangleShape
This method returns the bounding box of the RasterSource.

Exceptions

InvalidOperationException
In the event you attempt to call this method on a image source which has not been opened, it will throw an InvalidOperationException.

Remarks:

This method returns the bounding box of the RasterSource.

Events

StreamLoading

This event allows you to pass in your own stream to represent the image.

public event EventHandler<StreamLoadingEventArgs> StreamLoading;

Remarks:

If you wish, you can pass in your own stream to represent the image. The stream can come from a variety of places, including isolated storage, a compressed file, or an encrypted stream. When the image is finished with the stream it will dispose of it, so be sure to keep this in mind when passing the stream in. If you do not pass in an alternate stream, the class will attempt to load the file from the file system using the PathFilename property.

OpeningRasterSource

This event is called before the opening of the RasterSource.

public event EventHandler<OpeningRasterSourceEventArgs> OpeningRasterSource;

Remarks:

This event is called before the opening of the RasterSource. Technically, this event is called after the calling of the Open method on the RasterSource, but before the protected OpenCore method.

It is typical that the RasterSource may be opened and closed may times during the life cycle of your application. The type of control the MapEngine is embedded in will dictate how often this happens. For example, in the case of the Web Edition, each time a RasterSource is in the Ajax or Post Back part of the page cycle, it will close the RasterSource before returning back to the client. This is to conserve resources, as the web is a connection-less environment. In the case of the Desktop Edition, we can keep the RasterSource open, knowing that we can maintain a persistent connection.

OpenedRasterSource

This event is called after the opening of the RasterSource.

public event EventHandler<OpenedRasterSourceEventArgs> OpenedRasterSource;

Remarks:

This event is called after the opening of the RasterSource. Technically, this event is called after the calling of the Open method on the RasterSource and after the protected OpenCore method is called.

It is typical that the RasterSource may be opened and closed may times during the life cycle of your application. The type of control the MapEngine is embedded in will dictate how often this happens. For example, in the case of the Web Edition, each time a RasterSource is in the Ajax or Post Back part of the page cycle, it will close the RasterSource before returning back to the client. This is to conserve resources, as the web is a connection-less environment. In the case of the Desktop Edition, we can keep the RasterSource open, knowing that we can maintain a persistent connection.

ClosingRasterSource

This event is called before the closing of the RasterSource.

public event EventHandler<ClosingRasterSourceEventArgs> ClosingRasterSource;

Remarks:

This event is called before the closing of the RasterSource. Technically, this event is called after the calling of the Close method on the RasterSource, but before the protected CloseCore method.

It is typical that the RasterSource may be opened and closed may times during the life cycle of your application. The type of control the MapEngine is embedded in will dictate how often this happens. For example, in the case of the Web Edition, each time a RasterSource is in the Ajax or Post Back part of the page cycle, it will close the RasterSource before returning back to the client. This is to conserve resources, as the web is a connection-less environment. In the case of the Desktop Edition, we can keep the RasterSource open, knowing that we can maintain a persistent connection.

ClosedRasterSource

This event is called after the closing of the RasterSource.

public event EventHandler<ClosedRasterSourceEventArgs> ClosedRasterSource;

Remarks:

This event is called after the closing of the RasterSource. Technically, this event is called after the calling of the Close method on the RasterSource and after the protected CloseCore method.

It is typical that the RasterSource may be opened and closed may times during the life cycle of your application. The type of control the MapEngine is embedded in will dictate how often this happens. For example, in the case of the Web Edition, each time a RasterSource is in the Ajax or Post Back part of the page cycle, it will close the RasterSource before returning back to the client. This is to conserve resources, as the web is a connection-less environment. In the case of the Desktop Edition, we can keep the RasterSource open, knowing that we can maintain a persistent connection.