Classes | Public Types | Public Member Functions | Static Public Attributes

Image Class Reference

Holds a fixed-size bitmap. More...

List of all members.

Classes

class  BitmapData
 Retrieves a section of an image as raw pixel data, so it can be read or written to. More...
class  SharedImage
 This is a base class for task-specific types of image. More...

Public Types

enum  PixelFormat { UnknownFormat, RGB, ARGB, SingleChannel }
enum  ImageType { SoftwareImage = 0, NativeImage }

Public Member Functions

 Image ()
 Creates a null image.
 Image (PixelFormat format, int imageWidth, int imageHeight, bool clearImage, ImageType type=NativeImage)
 Creates an image with a specified size and format.
 Image (const Image &other)
 Creates a shared reference to another image.
Imageoperator= (const Image &)
 Makes this image refer to the same underlying image as another object.
 ~Image ()
 Destructor.
bool operator== (const Image &other) const noexcept
 Returns true if the two images are referring to the same internal, shared image.
bool operator!= (const Image &other) const noexcept
 Returns true if the two images are not referring to the same internal, shared image.
bool isValid () const noexcept
 Returns true if this image isn't null.
bool isNull () const noexcept
 Returns true if this image is not valid.
int getWidth () const noexcept
 Returns the image's width (in pixels).
int getHeight () const noexcept
 Returns the image's height (in pixels).
const Rectangle< int > getBounds () const noexcept
 Returns a rectangle with the same size as this image.
PixelFormat getFormat () const noexcept
 Returns the image's pixel format.
bool isARGB () const noexcept
 True if the image's format is ARGB.
bool isRGB () const noexcept
 True if the image's format is RGB.
bool isSingleChannel () const noexcept
 True if the image's format is a single-channel alpha map.
bool hasAlphaChannel () const noexcept
 True if the image contains an alpha-channel.
void clear (const Rectangle< int > &area, const Colour &colourToClearTo=Colour(0x00000000))
 Clears a section of the image with a given colour.
Image rescaled (int newWidth, int newHeight, Graphics::ResamplingQuality quality=Graphics::mediumResamplingQuality) const
 Returns a rescaled version of this image.
Image convertedToFormat (PixelFormat newFormat) const
 Returns a version of this image with a different image format.
void duplicateIfShared ()
 Makes sure that no other Image objects share the same underlying data as this one.
Image getClippedImage (const Rectangle< int > &area) const
 Returns an image which refers to a subsection of this image.
const Colour getPixelAt (int x, int y) const
 Returns the colour of one of the pixels in the image.
void setPixelAt (int x, int y, const Colour &colour)
 Sets the colour of one of the image's pixels.
void multiplyAlphaAt (int x, int y, float multiplier)
 Changes the opacity of a pixel.
void multiplyAllAlphas (float amountToMultiplyBy)
 Changes the overall opacity of the image.
void desaturate ()
 Changes all the colours to be shades of grey, based on their current luminosity.
void setPixelData (int destX, int destY, int destW, int destH, const uint8 *sourcePixelData, int sourceLineStride)
 Copies some pixel values to a rectangle of the image.
void moveImageSection (int destX, int destY, int sourceX, int sourceY, int width, int height)
 Copies a section of the image to somewhere else within itself.
void createSolidAreaMask (RectangleList &result, float alphaThreshold=0.5f) const
 Creates a RectangleList containing rectangles for all non-transparent pixels of the image.
NamedValueSetgetProperties () const
 Returns a NamedValueSet that is attached to the image and which can be used for associating custom values with it.
LowLevelGraphicsContextcreateLowLevelContext () const
 Creates a context suitable for drawing onto this image.
int getReferenceCount () const noexcept
 Returns the number of Image objects which are currently referring to the same internal shared image data.
SharedImagegetSharedImage () const noexcept
 Image (SharedImage *instance)

Static Public Attributes

static const Image null
 A null Image object that can be used when you need to return an invalid image.

Detailed Description

Holds a fixed-size bitmap.

The image is stored in either 24-bit RGB or 32-bit premultiplied-ARGB format.

To draw into an image, create a Graphics object for it. e.g.

    // create a transparent 500x500 image..
    Image myImage (Image::RGB, 500, 500, true);

    Graphics g (myImage);
    g.setColour (Colours::red);
    g.fillEllipse (20, 20, 300, 200);  // draws a red ellipse in our image.

Other useful ways to create an image are with the ImageCache class, or the ImageFileFormat, which provides a way to load common image files.

See also:
Graphics, ImageFileFormat, ImageCache, ImageConvolutionKernel

Member Enumeration Documentation

Enumerator:
UnknownFormat 
RGB 

< each pixel is a 3-byte packed RGB colour value.

For byte order, see the PixelRGB class.

ARGB 

< each pixel is a 4-byte ARGB premultiplied colour value.

For byte order, see the PixelARGB class.

SingleChannel 

< each pixel is a 1-byte alpha channel value.

Enumerator:
SoftwareImage 
NativeImage 

Constructor & Destructor Documentation

Image::Image (  )

Creates a null image.

Image::Image ( PixelFormat  format,
int  imageWidth,
int  imageHeight,
bool  clearImage,
ImageType  type = NativeImage 
)

Creates an image with a specified size and format.

Parameters:
formatthe number of colour channels in the image
imageWidththe desired width of the image, in pixels - this value must be greater than zero (otherwise a width of 1 will be used)
imageHeightthe desired width of the image, in pixels - this value must be greater than zero (otherwise a height of 1 will be used)
clearImageif true, the image will initially be cleared to black (if it's RGB) or transparent black (if it's ARGB). If false, the image may contain junk initially, so you need to make sure you overwrite it thoroughly.
typethe type of image - this lets you specify whether you want a purely memory-based image, or one that may be managed by the OS if possible.
Image::Image ( const Image other )

Creates a shared reference to another image.

This won't create a duplicate of the image - when Image objects are copied, they simply point to the same shared image data. To make sure that an Image object has its own unique, unshared internal data, call duplicateIfShared().

Image::~Image (  )

Destructor.

Image::Image ( SharedImage instance ) [explicit]

Member Function Documentation

Image& Image::operator= ( const Image  )

Makes this image refer to the same underlying image as another object.

This won't create a duplicate of the image - when Image objects are copied, they simply point to the same shared image data. To make sure that an Image object has its own unique, unshared internal data, call duplicateIfShared().

bool Image::operator== ( const Image other ) const

Returns true if the two images are referring to the same internal, shared image.

bool Image::operator!= ( const Image other ) const

Returns true if the two images are not referring to the same internal, shared image.

bool Image::isValid (  ) const

Returns true if this image isn't null.

If you create an Image with the default constructor, it has no size or content, and is null until you reassign it to an Image which contains some actual data. The isNull() method is the opposite of isValid().

See also:
isNull

Referenced by FillType::isTiledImage().

bool Image::isNull (  ) const

Returns true if this image is not valid.

If you create an Image with the default constructor, it has no size or content, and is null until you reassign it to an Image which contains some actual data. The isNull() method is the opposite of isValid().

See also:
isValid

Referenced by FillType::isColour().

int Image::getWidth (  ) const

Returns the image's width (in pixels).

int Image::getHeight (  ) const

Returns the image's height (in pixels).

const Rectangle<int> Image::getBounds (  ) const

Returns a rectangle with the same size as this image.

The rectangle's origin is always (0, 0).

PixelFormat Image::getFormat (  ) const

Returns the image's pixel format.

bool Image::isARGB (  ) const

True if the image's format is ARGB.

bool Image::isRGB (  ) const

True if the image's format is RGB.

bool Image::isSingleChannel (  ) const

True if the image's format is a single-channel alpha map.

bool Image::hasAlphaChannel (  ) const

True if the image contains an alpha-channel.

void Image::clear ( const Rectangle< int > &  area,
const Colour colourToClearTo = Colour(0x00000000) 
)

Clears a section of the image with a given colour.

This won't do any alpha-blending - it just sets all pixels in the image to the given colour (which may be non-opaque if the image has an alpha channel).

Image Image::rescaled ( int  newWidth,
int  newHeight,
Graphics::ResamplingQuality  quality = Graphics::mediumResamplingQuality 
) const

Returns a rescaled version of this image.

A new image is returned which is a copy of this one, rescaled to the given size.

Note that if the new size is identical to the existing image, this will just return a reference to the original image, and won't actually create a duplicate.

Image Image::convertedToFormat ( PixelFormat  newFormat ) const

Returns a version of this image with a different image format.

A new image is returned which has been converted to the specified format.

Note that if the new format is no different to the current one, this will just return a reference to the original image, and won't actually create a copy.

void Image::duplicateIfShared (  )

Makes sure that no other Image objects share the same underlying data as this one.

If no other Image objects refer to the same shared data as this one, this method has no effect. But if there are other references to the data, this will create a new copy of the data internally.

Call this if you want to draw onto the image, but want to make sure that this doesn't affect any other code that may be sharing the same data.

See also:
getReferenceCount
Image Image::getClippedImage ( const Rectangle< int > &  area ) const

Returns an image which refers to a subsection of this image.

This will not make a copy of the original - the new image will keep a reference to it, so that if the original image is changed, the contents of the subsection will also change. Likewise if you draw into the subimage, you'll also be drawing onto that area of the original image. Note that if you use operator= to make the original Image object refer to something else, the subsection image won't pick up this change, it'll remain pointing at the original.

The area passed-in will be clipped to the bounds of this image, so this may return a smaller image than the area you asked for, or even a null image if the area was out-of-bounds.

const Colour Image::getPixelAt ( int  x,
int  y 
) const

Returns the colour of one of the pixels in the image.

If the co-ordinates given are beyond the image's boundaries, this will return Colours::transparentBlack.

See also:
setPixelAt, Image::BitmapData::getPixelColour
void Image::setPixelAt ( int  x,
int  y,
const Colour colour 
)

Sets the colour of one of the image's pixels.

If the co-ordinates are beyond the image's boundaries, then nothing will happen.

Note that this won't do any alpha-blending, it'll just replace the existing pixel with the given one. The colour's opacity will be ignored if this image doesn't have an alpha-channel.

See also:
getPixelAt, Image::BitmapData::setPixelColour
void Image::multiplyAlphaAt ( int  x,
int  y,
float  multiplier 
)

Changes the opacity of a pixel.

This only has an effect if the image has an alpha channel and if the given co-ordinates are inside the image's boundary.

The multiplier must be in the range 0 to 1.0, and the current alpha at the given co-ordinates will be multiplied by this value.

See also:
setPixelAt
void Image::multiplyAllAlphas ( float  amountToMultiplyBy )

Changes the overall opacity of the image.

This will multiply the alpha value of each pixel in the image by the given amount (limiting the resulting alpha values between 0 and 255). This allows you to make an image more or less transparent.

If the image doesn't have an alpha channel, this won't have any effect.

void Image::desaturate (  )

Changes all the colours to be shades of grey, based on their current luminosity.

void Image::setPixelData ( int  destX,
int  destY,
int  destW,
int  destH,
const uint8 sourcePixelData,
int  sourceLineStride 
)

Copies some pixel values to a rectangle of the image.

The format of the pixel data must match that of the image itself, and the rectangle supplied must be within the image's bounds.

void Image::moveImageSection ( int  destX,
int  destY,
int  sourceX,
int  sourceY,
int  width,
int  height 
)

Copies a section of the image to somewhere else within itself.

void Image::createSolidAreaMask ( RectangleList result,
float  alphaThreshold = 0.5f 
) const

Creates a RectangleList containing rectangles for all non-transparent pixels of the image.

Parameters:
resultthe list that will have the area added to it
alphaThresholdfor a semi-transparent image, any pixels whose alpha is above this level will be considered opaque
NamedValueSet* Image::getProperties (  ) const

Returns a NamedValueSet that is attached to the image and which can be used for associating custom values with it.

If this is a null image, this will return a null pointer.

LowLevelGraphicsContext* Image::createLowLevelContext (  ) const

Creates a context suitable for drawing onto this image.

Don't call this method directly! It's used internally by the Graphics class.

int Image::getReferenceCount (  ) const

Returns the number of Image objects which are currently referring to the same internal shared image data.

See also:
duplicateIfShared
SharedImage* Image::getSharedImage (  ) const

Member Data Documentation

const Image Image::null [static]

A null Image object that can be used when you need to return an invalid image.

This object is the equivalient to an Image created with the default constructor.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines