Game Development Reference
In-Depth Information
The System.Drawing namespace supports a variety of image formats, but some texture
formats, such as DDS, are not supported unless a custom loader is written or the
data is loaded through Managed Direct3D. The control will display textures that
have been resized to fit within a thumbnail control, with support for both single
and multiple selection of texture thumbnails. Each thumbnail will have a label for
the filename and a label for the dimensions of the original image. All thumbnails
will sit within a parent container control.
Swappable Loader Interface
One of the goals outlined for this component is the ability to switch the loader that
processes the image files. While Managed Direct3D and Windows GDI+ are the
only loaders supported by this chapter, it would be advantageous to design the
component so that any loader implementing the appropriate interface could be
plugged into the component. This component makes use of an interface and
abstract class to define the common interface of all image loaders so that they can
be swapped in and out.
The interface provides two Load methods, which are used to create a Bitmap object
from an image file on the hard drive or from a memory stream. Some loaders may
also require a handle to a resource, such as a window handle for the Direct3D
loader, so this interface provides the ContextHandle property to support this
requirement.
The following code defines the base loader interface and abstract class.
public interface IAbstractLoader
{
System.IntPtr ContextHandle
{
get;
set;
}
Bitmap Load(string fileName);
Bitmap Load(MemoryStream stream);
}
With the loader interface defined, it is time to define the abstract loader class that
implements the interface. This class stores the context handle of a control that cer-
tain loaders may need to operate correctly. The GDI+ loader does not use this, but
Search Nedrilad ::




Custom Search