Eve Application Development

Michael L Brereton - 30 December 2007, http://www.ewesoft.com/

 

Beginners Guide - Contents

<< Previous: Dynamic Controls

>> Next: Drawing On Controls

Images and Pictures

Eve Application Development 1

Images and Pictures 1

Images and Pictures 1

PixelBuffers 2

 

 

The interface ImageData (eve.sys) represents a 2D Object that has a particular width and height and can provide pixel data as raw scan lines and as ARGB formatted int values (Alpha-Red-Green-Blue at 8 bits per channel). It is used to represent an abstract Object that contains image pixel data but makes no assumptions about how that data is stored or how it is to be rendered to any graphics entity. You will generally not need to implement objects of this class unless you are doing specialized image processing.

 

The interface Drawable (eve.fx) represents a 2D Object that has a particular width and height and “knows” how to draw itself onto a Graphics object.

 

The interface IImage (eve.fx) inherits from ImageData and Drawable and represents an object with pixel data that knows how to draw itself onto a Graphics object. IImage is the base interface implemented by most of the image based classes in the Eve library.

 

Images and Pictures

 

The class Image (eve.fx) is a standard bitmapped image that can be drawn on using a Graphics object – similar to the java.awt.BufferedImage class. Its implementation is related closely to the native OS and it usually is linked to a native object that represents a drawable bitmap (e.g. an HBITMAP on Windows).

 

You can draw to an Image by creating a Graphics object for the image using new Graphics(Image im) and then drawing onto that Graphics. You can convert an Image to a Picture by calling toPicture() on the Image.

 

The class Picture (eve.fx) is an immutable bitmapped image that is optimized for fastest drawing to a Graphics object. You cannot draw on a Picture so it must be created from:

 

1.      Decoding a formatted image (in JPEG, GIF, BMP or PNG format).

2.      From raw pixel data from any ImageData source (e.g. an Image).

 

The main constructors used for decoding from formatted image bytes are:

 

public Picture(String imageName);

 

The imageName is the name of the image resource (which may reside as a file, applet resource or eve file resource). This method actually creates a FormattedDataSource using the imageName as the source of the bytes and then uses the constructor below:

 

public Picture(FormattedDataSource source,Object maskObject,int options);

 

All the other Picture() constructors that decode formatted bytes eventually call this constructor. The source parameter is the source of the formatted image bytes. The maskObject can be null, it can be a Color (specifying the color that should be considered transparent), it can be a Mask object (which defines a transparency bitmap) or it can be the name of a bitmapped image resource which will then be converted to a Mask object.

 

It is recommended that you store images in PNG format, in which case you will not need to use maskObject at all since PNG images can specify transparency (alpha) values for each pixel.

 

No options are currently defined for Picture constructors so you should set options to 0.

 

You can create a Picture from any ImageData object using:

 

public Picture(ImageData source,Object maskObject,int options);

 

MaskObject is the same as described above and no options are currently defined.

 

If you only wish to create a Picture from a section of an existing image then you should first create a PixelBuffer and then convert the PixelBuffer to a Picture.

PixelBuffers

 

A PixelBuffer is an IImage that stores its pixels completely in an int array – with no underlying OS specific image resource. It can be used for a number of purposes:

 

1.      To access and directly manipulate the pixel data for an image or a section of an image.

2.      To transform pixel data in some way.

3.      To compose images with arbitrary alpha values.

 

The third function is necessary because you cannot “paint” pixel data with transparency values to a Graphics object. Although the Graphics object can alpha-blend an Image into the destination drawing surface, the final pixels of the destination surface will always be fully opaque regardless of the alpha value of the source image. A PixelBuffer provides methods that you can use to create an image with transparent sections using standard Graphics drawing primitives. However this will be covered in a chapter on advanced 2D imaging.

 

The pixel int array values for an PixelBuffer is available through the int[] getBuffer() method. The size of this array will always be a minimum of width*height with each int value representing a pixel in ARGB format. You can create a PixelBuffer from an existing image, a section of an existing image, a scaled section of an existing image or from formatted image bytes. Once you create the PixelBuffer you can access the pixels directly, perform a transformation on the pixels, scale or set the transparency values of pixels or use drawing primitives to add to the image. Once complete  you can call toPicture() or toImage() to convert to a Picture or Image object.