JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::Image Class Referencefinal

Holds a fixed-size bitmap. More...

#include <juce_Image.h>

Collaboration diagram for juce::Image:

Classes

class  BitmapData
 Retrieves a section of an image as raw pixel data, so it can be read or written to. More...
 

Public Types

enum  PixelFormat {
  UnknownFormat,
  RGB,
  ARGB,
  SingleChannel
}
 

Public Member Functions

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

Private Attributes

ReferenceCountedObjectPtr< ImagePixelDataimage
 

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

@tags{Graphics}

Member Enumeration Documentation

◆ PixelFormat

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.

Constructor & Destructor Documentation

◆ Image() [1/6]

juce::Image::Image ( )
noexcept

Creates a null image.

◆ Image() [2/6]

juce::Image::Image ( PixelFormat  format,
int  imageWidth,
int  imageHeight,
bool  clearImage 
)

Creates an image with a specified size and format.

The image's internal type will be of the NativeImageType class - to specify a different type, use the other constructor, which takes an ImageType to use.

Parameters
formatthe preferred pixel format. Note that this is only a hint which is passed to the ImageType class - different ImageTypes may not support all formats, so may substitute e.g. ARGB for RGB.
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.

◆ Image() [3/6]

juce::Image::Image ( PixelFormat  format,
int  imageWidth,
int  imageHeight,
bool  clearImage,
const ImageType type 
)

Creates an image with a specified size and format.

Parameters
formatthe preferred pixel format. Note that this is only a hint which is passed to the ImageType class - different ImageTypes may not support all formats, so may substitute e.g. ARGB for RGB.
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 the internal format that will be used to allocate and manage the image data.

◆ Image() [4/6]

juce::Image::Image ( const Image )
noexcept

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() [5/6]

juce::Image::Image ( Image &&  )
noexcept

Move constructor.

◆ ~Image()

juce::Image::~Image ( )

Destructor.

◆ Image() [6/6]

juce::Image::Image ( ReferenceCountedObjectPtr< ImagePixelData )
explicitnoexcept

Member Function Documentation

◆ clear()

void juce::Image::clear ( const Rectangle< int > &  area,
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).

◆ convertedToFormat()

Image juce::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.

◆ createCopy()

Image juce::Image::createCopy ( ) const

Creates a copy of this image.

Note that it's usually more efficient to use duplicateIfShared(), because it may not be necessary to copy an image if nothing else is using it.

See also
getReferenceCount

◆ createLowLevelContext()

std::unique_ptr<LowLevelGraphicsContext> juce::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.

◆ createSolidAreaMask()

void juce::Image::createSolidAreaMask ( RectangleList< int > &  result,
float  alphaThreshold 
) 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

◆ desaturate()

void juce::Image::desaturate ( )

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

◆ duplicateIfShared()

void juce::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

◆ getBounds()

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

Returns a rectangle with the same size as this image.

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

Referenced by juce::RenderingHelpers::SavedStateBase< SoftwareRendererSavedState >::clipToImageAlpha(), and juce::RenderingHelpers::SavedStateBase< SoftwareRendererSavedState >::renderImage().

◆ getClippedImage()

Image juce::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.

◆ getFormat()

PixelFormat juce::Image::getFormat ( ) const
noexcept

Returns the image's pixel format.

◆ getHeight()

int juce::Image::getHeight ( ) const
noexcept

Returns the image's height (in pixels).

Referenced by juce::RenderingHelpers::SavedStateBase< SoftwareRendererSavedState >::renderImage().

◆ getPixelAt()

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

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

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

See also
setPixelAt, Image::BitmapData::getPixelColour

◆ getPixelData()

ImagePixelData* juce::Image::getPixelData ( ) const
inlinenoexcept

◆ getProperties()

NamedValueSet* juce::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.

◆ getReferenceCount()

int juce::Image::getReferenceCount ( ) const
noexcept

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

See also
duplicateIfShared

◆ getWidth()

int juce::Image::getWidth ( ) const
noexcept

Returns the image's width (in pixels).

Referenced by juce::RenderingHelpers::SavedStateBase< SoftwareRendererSavedState >::renderImage().

◆ hasAlphaChannel()

bool juce::Image::hasAlphaChannel ( ) const
noexcept

True if the image contains an alpha-channel.

Referenced by juce::RenderingHelpers::SavedStateBase< SoftwareRendererSavedState >::clipToImageAlpha().

◆ isARGB()

bool juce::Image::isARGB ( ) const
noexcept

True if the image's format is ARGB.

◆ isNull()

bool juce::Image::isNull ( ) const
inlinenoexcept

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

◆ isRGB()

bool juce::Image::isRGB ( ) const
noexcept

True if the image's format is RGB.

◆ isSingleChannel()

bool juce::Image::isSingleChannel ( ) const
noexcept

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

◆ isValid()

bool juce::Image::isValid ( ) const
inlinenoexcept

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

◆ moveImageSection()

void juce::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.

◆ multiplyAllAlphas()

void juce::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.

◆ multiplyAlphaAt()

void juce::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 coordinates are inside the image's boundary.

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

See also
setPixelAt

◆ operator!=()

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

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

◆ operator=() [1/2]

Image& juce::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().

◆ operator=() [2/2]

Image& juce::Image::operator= ( Image &&  )
noexcept

Move assignment operator.

◆ operator==()

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

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

◆ rescaled()

juce::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.

Note
Carefully choose the width as height, as this method is not restricted to the original image aspect ratio.

◆ setPixelAt()

void juce::Image::setPixelAt ( int  x,
int  y,
Colour  colour 
)

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

If the coordinates 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

Member Data Documentation

◆ image

ReferenceCountedObjectPtr<ImagePixelData> juce::Image::image
private

The documentation for this class was generated from the following files:
juce::Image::RGB
@ RGB
< each pixel is a 3-byte packed RGB colour value.
Definition: juce_Image.h:66
juce::Image::Image
Image() noexcept
Creates a null image.
juce::Colours::red
const Colour red
Definition: juce_Colours.h:157
juce::gl::g
GLboolean GLboolean g
Definition: juce_gl.h:1931