Version: 3.2.5
wxPixelData< Image, PixelFormat > Class Template Reference

#include <wx/rawbmp.h>

+ Inheritance diagram for wxPixelData< Image, PixelFormat >:

Detailed Description

template<class Image, class PixelFormat = wxPixelFormatFor<Image>>
class wxPixelData< Image, PixelFormat >

A class template with ready to use implementations for getting direct and efficient access to wxBitmap's internal data and wxImage's internal data through a standard interface.

It is possible to extend this class (interface) to other types of image content.

Implemented on Windows, GTK+ and macOS:

  • wxNativePixelData: Class to access to wxBitmap's internal data without alpha channel (RGB).
  • wxAlphaPixelData: Class to access to wxBitmap's internal data with alpha channel (RGBA).

Implemented everywhere:

  • wxImagePixelData: Class to access to wxImage's internal data with alpha channel (RGBA).

wxMSW note: efficient access is only possible to the bits of the so called device independent bitmaps (DIB) under MSW. To ensure that wxBitmap uses a DIB internally and not a device dependent bitmap (DDB), you need to pass an explicit depth to its ctor, i.e. either 24 or 32, as by default wxBitmap creates a DDB of the screen depth.

Example:

wxBitmap bmp(width, size, 24); // explicit depth important under MSW
wxNativePixelData data(bmp);
if ( !data )
{
// ... raw access to bitmap data unavailable, do something else ...
return;
}
if ( data.GetWidth() < 20 || data.GetHeight() < 20 )
{
// ... complain: the bitmap it too small ...
return;
}
wxNativePixelData::Iterator p(data);
// we draw a (10, 10)-(20, 20) rect manually using the given r, g, b
p.Offset(data, 10, 10);
for ( int y = 0; y < 10; ++y )
{
wxNativePixelData::Iterator rowStart = p;
for ( int x = 0; x < 10; ++x, ++p )
{
p.Red() = r;
p.Green() = g;
p.Blue() = b;
}
p = rowStart;
p.OffsetY(data, 1);
}
This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...
Definition: bitmap.h:212

Library:  wxCore
Category:  Graphics Device Interface (GDI)
See also
wxBitmap, wxImage

Classes

class  Iterator
 The iterator of class wxPixelData. More...
 

Public Types

typedef Image ImageType
 The type of the class we're working with. More...
 

Public Member Functions

 wxPixelData (Image &image)
 Create pixel data object representing the entire image. More...
 
 wxPixelData (Image &i, const wxRect &rect)
 Create pixel data object representing the area of the image defined by rect. More...
 
 wxPixelData (Image &i, const wxPoint &pt, const wxSize &sz)
 Create pixel data object representing the area of the image defined by pt and sz. More...
 
 operator bool () const
 Return true of if we could get access to bitmap data successfully. More...
 
Iterator GetPixels () const
 Return the iterator pointing to the origin of the image. More...
 
wxPoint GetOrigin () const
 Returns origin of the rectangular region this wxPixelData represents. More...
 
int GetWidth () const
 Return width of the region this wxPixelData represents. More...
 
int GetHeight () const
 Return height of the region this wxPixelData represents. More...
 
wxSize GetSize () const
 Return the area which this wxPixelData represents in the image. More...
 
int GetRowStride () const
 Return the distance between two rows. More...
 

Member Typedef Documentation

◆ ImageType

template<class Image , class PixelFormat = wxPixelFormatFor<Image>>
typedef Image wxPixelData< Image, PixelFormat >::ImageType

The type of the class we're working with.

Constructor & Destructor Documentation

◆ wxPixelData() [1/3]

template<class Image , class PixelFormat = wxPixelFormatFor<Image>>
wxPixelData< Image, PixelFormat >::wxPixelData ( Image &  image)

Create pixel data object representing the entire image.

◆ wxPixelData() [2/3]

template<class Image , class PixelFormat = wxPixelFormatFor<Image>>
wxPixelData< Image, PixelFormat >::wxPixelData ( Image &  i,
const wxRect rect 
)

Create pixel data object representing the area of the image defined by rect.

◆ wxPixelData() [3/3]

template<class Image , class PixelFormat = wxPixelFormatFor<Image>>
wxPixelData< Image, PixelFormat >::wxPixelData ( Image &  i,
const wxPoint pt,
const wxSize sz 
)

Create pixel data object representing the area of the image defined by pt and sz.

Member Function Documentation

◆ GetHeight()

template<class Image , class PixelFormat = wxPixelFormatFor<Image>>
int wxPixelData< Image, PixelFormat >::GetHeight ( ) const

Return height of the region this wxPixelData represents.

◆ GetOrigin()

template<class Image , class PixelFormat = wxPixelFormatFor<Image>>
wxPoint wxPixelData< Image, PixelFormat >::GetOrigin ( ) const

Returns origin of the rectangular region this wxPixelData represents.

◆ GetPixels()

template<class Image , class PixelFormat = wxPixelFormatFor<Image>>
Iterator wxPixelData< Image, PixelFormat >::GetPixels ( ) const

Return the iterator pointing to the origin of the image.

◆ GetRowStride()

template<class Image , class PixelFormat = wxPixelFormatFor<Image>>
int wxPixelData< Image, PixelFormat >::GetRowStride ( ) const

Return the distance between two rows.

◆ GetSize()

template<class Image , class PixelFormat = wxPixelFormatFor<Image>>
wxSize wxPixelData< Image, PixelFormat >::GetSize ( ) const

Return the area which this wxPixelData represents in the image.

◆ GetWidth()

template<class Image , class PixelFormat = wxPixelFormatFor<Image>>
int wxPixelData< Image, PixelFormat >::GetWidth ( ) const

Return width of the region this wxPixelData represents.

◆ operator bool()

template<class Image , class PixelFormat = wxPixelFormatFor<Image>>
wxPixelData< Image, PixelFormat >::operator bool ( ) const

Return true of if we could get access to bitmap data successfully.